From 938d015bbdd9234b123b94d4dc82be4f01b501c2 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 18 Jun 2025 19:17:17 +0000 Subject: [PATCH 01/15] Create untracked state inside create_global_ctxt. --- compiler/rustc_interface/src/passes.rs | 18 ++++-------------- compiler/rustc_middle/src/ty/context.rs | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index cb41974af41b0..e90e67a943300 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -11,9 +11,7 @@ use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::{CompiledModules, CrateInfo}; use rustc_data_structures::indexmap::IndexMap; use rustc_data_structures::steal::Steal; -use rustc_data_structures::sync::{ - AppendOnlyIndexVec, DynSend, DynSync, FreezeLock, WorkerLocal, par_fns, -}; +use rustc_data_structures::sync::{DynSend, DynSync, WorkerLocal, par_fns}; use rustc_data_structures::thousands; use rustc_errors::timings::TimingSection; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level}; @@ -21,8 +19,7 @@ use rustc_expand::base::{ExtCtxt, LintStoreExpand}; use rustc_feature::Features; use rustc_fs_util::try_canonicalize; use rustc_hir::attrs::AttributeKind; -use rustc_hir::def_id::{LOCAL_CRATE, StableCrateId, StableCrateIdMap}; -use rustc_hir::definitions::Definitions; +use rustc_hir::def_id::{LOCAL_CRATE, StableCrateId}; use rustc_hir::limit::Limit; use rustc_hir::{Attribute, MaybeOwner, Target, find_attr}; use rustc_incremental::setup_dep_graph; @@ -38,7 +35,6 @@ use rustc_passes::{abi_test, input_stats, layout_test}; use rustc_resolve::{Resolver, ResolverOutputs}; use rustc_session::Session; use rustc_session::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType}; -use rustc_session::cstore::Untracked; use rustc_session::errors::feature_err; use rustc_session::output::{filename_for_input, invalid_output_for_target}; use rustc_session::search_paths::PathKind; @@ -943,13 +939,7 @@ pub fn create_and_enter_global_ctxt FnOnce(TyCtxt<'tcx>) -> T>( let dep_graph = setup_dep_graph(sess, crate_name, stable_crate_id); - let cstore = - FreezeLock::new(Box::new(CStore::new(compiler.codegen_backend.metadata_loader())) as _); - let definitions = FreezeLock::new(Definitions::new(stable_crate_id)); - - let stable_crate_ids = FreezeLock::new(StableCrateIdMap::default()); - let untracked = - Untracked { cstore, source_span: AppendOnlyIndexVec::new(), definitions, stable_crate_ids }; + let cstore = Box::new(CStore::new(compiler.codegen_backend.metadata_loader())) as _; // We're constructing the HIR here; we don't care what we will // read, since we haven't even constructed the *input* to @@ -990,7 +980,7 @@ pub fn create_and_enter_global_ctxt FnOnce(TyCtxt<'tcx>) -> T>( stable_crate_id, &arena, &hir_arena, - untracked, + cstore, dep_graph, rustc_query_impl::make_dep_kind_vtables(&arena), rustc_query_impl::query_system( diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index bbe241c574d41..a520e36a23d7e 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -26,11 +26,12 @@ use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap}; use rustc_data_structures::stable_hasher::StableHash; use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{ - self, DynSend, DynSync, FreezeReadGuard, Lock, RwLock, WorkerLocal, + self, AppendOnlyIndexVec, DynSend, DynSync, FreezeLock, FreezeReadGuard, Lock, RwLock, + WorkerLocal, }; use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, MultiSpan}; use rustc_hir::def::DefKind; -use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId}; +use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, StableCrateIdMap}; use rustc_hir::definitions::{DefPathData, Definitions, PerParentDisambiguatorState}; use rustc_hir::intravisit::VisitorExt; use rustc_hir::lang_items::LangItem; @@ -936,7 +937,7 @@ impl<'tcx> TyCtxt<'tcx> { stable_crate_id: StableCrateId, arena: &'tcx WorkerLocal>, hir_arena: &'tcx WorkerLocal>, - untracked: Untracked, + cstore: Box, dep_graph: DepGraph, dep_kind_vtables: &'tcx [DepKindVTable<'tcx>], query_system: QuerySystem<'tcx>, @@ -945,6 +946,17 @@ impl<'tcx> TyCtxt<'tcx> { jobserver_proxy: Arc, f: impl FnOnce(TyCtxt<'tcx>) -> T, ) -> T { + let cstore = FreezeLock::new(cstore); + let definitions = FreezeLock::new(Definitions::new(stable_crate_id)); + + let stable_crate_ids = FreezeLock::new(StableCrateIdMap::default()); + let untracked = Untracked { + cstore, + source_span: AppendOnlyIndexVec::new(), + definitions, + stable_crate_ids, + }; + let data_layout = s.target.parse_data_layout().unwrap_or_else(|err| { s.dcx().emit_fatal(err); }); From 439b5d63a23dd1b95aec4b08bb85ccf2e905d673 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Sat, 25 Apr 2026 16:21:44 +0000 Subject: [PATCH 02/15] Make `create_def` a query. --- compiler/rustc_hir/src/definitions.rs | 60 +++++++++++------------- compiler/rustc_middle/src/queries.rs | 12 +++++ compiler/rustc_middle/src/query/erase.rs | 1 + compiler/rustc_middle/src/query/keys.rs | 9 ++++ compiler/rustc_middle/src/ty/context.rs | 60 +++++++++++++++++------- 5 files changed, 92 insertions(+), 50 deletions(-) diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index e9801a8a5231b..6f757592aa6b0 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::StableHasher; use rustc_hashes::Hash64; use rustc_index::IndexVec; -use rustc_macros::{BlobDecodable, Decodable, Encodable, extension}; +use rustc_macros::{BlobDecodable, Decodable, Encodable, HashStable, extension}; use rustc_span::def_id::LocalDefIdMap; use rustc_span::{Symbol, kw, sym}; use tracing::{debug, instrument}; @@ -114,6 +114,28 @@ impl PerParentDisambiguatorState { next: Default::default(), } } + + /// If there are multiple definitions with the same DefPathData and the same parent, use + /// `self` to differentiate them. Distinct `PerParentDisambiguatorState` instances are not + /// guaranteed to generate unique disambiguators and should instead ensure that the `parent` + /// and `data` pair is distinct from other instances. + pub fn disambiguate( + &mut self, + _parent: LocalDefId, + data: DefPathData, + ) -> DisambiguatedDefPathData { + #[cfg(debug_assertions)] + debug_assert_eq!( + _parent, + self.parent.expect("must be set"), + "provided parent and parent in disambiguator must be the same" + ); + + let next_disamb = self.next.entry(data).or_insert(0); + let disambiguator = *next_disamb; + *next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow"); + DisambiguatedDefPathData { disambiguator, data } + } } #[extension(pub trait PerParentDisambiguatorsMap)] @@ -183,7 +205,7 @@ impl DefKey { /// between them. This introduces some artificial ordering dependency /// but means that if you have, e.g., two impls for the same type in /// the same module, they do get distinct `DefId`s. -#[derive(Copy, Clone, PartialEq, Debug, Encodable, BlobDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Encodable, BlobDecodable, HashStable)] pub struct DisambiguatedDefPathData { pub data: DefPathData, pub disambiguator: u32, @@ -277,7 +299,7 @@ impl DefPath { } /// New variants should only be added in synchronization with `enum DefKind`. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, BlobDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, BlobDecodable, HashStable)] pub enum DefPathData { // Root: these should only be used for the root nodes, because // they are treated specially by the `def_path` function. @@ -384,16 +406,7 @@ impl Definitions { } /// Creates a definition with a parent definition. - /// If there are multiple definitions with the same DefPathData and the same parent, use - /// `disambiguator` to differentiate them. Distinct `DisambiguatorState` instances are not - /// guaranteed to generate unique disambiguators and should instead ensure that the `parent` - /// and `data` pair is distinct from other instances. - pub fn create_def( - &mut self, - parent: LocalDefId, - data: DefPathData, - disambiguator: &mut PerParentDisambiguatorState, - ) -> LocalDefId { + pub fn create_def(&mut self, parent: LocalDefId, data: DisambiguatedDefPathData) -> LocalDefId { // We can't use `Debug` implementation for `LocalDefId` here, since it tries to acquire a // reference to `Definitions` and we're already holding a mutable reference. debug!( @@ -402,26 +415,9 @@ impl Definitions { ); // The root node must be created in `new()`. - assert!(data != DefPathData::CrateRoot); - - // Find the next free disambiguator for this key. - let disambiguator = { - #[cfg(debug_assertions)] - debug_assert_eq!( - parent, - disambiguator.parent.expect("must be set"), - "provided parent and parent in disambiguator must be the same" - ); + assert!(data.data != DefPathData::CrateRoot); - let next_disamb = disambiguator.next.entry(data).or_insert(0); - let disambiguator = *next_disamb; - *next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow"); - disambiguator - }; - let key = DefKey { - parent: Some(parent.local_def_index), - disambiguated_data: DisambiguatedDefPathData { data, disambiguator }, - }; + let key = DefKey { parent: Some(parent.local_def_index), disambiguated_data: data }; let parent_hash = self.table.def_path_hash(parent.local_def_index); let def_path_hash = key.compute_stable_hash(parent_hash); diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index f0c367beefd65..e572f7d236816 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -67,6 +67,7 @@ use rustc_hir::def::{DefKind, DocLinkResMap}; use rustc_hir::def_id::{ CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap, LocalDefIdSet, LocalModDefId, }; +use rustc_hir::definitions::DisambiguatedDefPathData; use rustc_hir::lang_items::{LangItem, LanguageItems}; use rustc_hir::{ItemLocalId, ItemLocalMap, PreciseCapturingArgKind, TraitCandidate}; use rustc_index::IndexVec; @@ -198,6 +199,17 @@ rustc_queries! { desc { "getting the source span" } } + /// Create a new definition. + /// + /// This query is meant to wrap a side-effect and return the resulting newly created + /// definition. In incremental mode, when replaying a query, this query caches the side-effect + /// to avoid performing it twice. + query create_def_raw(key: (LocalDefId, DisambiguatedDefPathData)) -> LocalDefId { + // Accesses untracked data + eval_always + desc { "create a new definition for `{}::{:?}`", tcx.def_path_str(key.0), key.1 } + } + /// Represents crate as a whole (as distinct from the top-level crate module). /// /// If you call `tcx.hir_crate(())` we will have to assume that any change diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index a6ff238ad6f0b..2f54b8bcd9fa8 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -214,6 +214,7 @@ impl_erasable_for_types_with_no_type_params! { rustc_hir::OpaqueTyOrigin, rustc_hir::def::DefKind, rustc_hir::def_id::DefId, + rustc_hir::def_id::LocalDefId, rustc_middle::middle::codegen_fn_attrs::SanitizerFnAttrs, rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault, rustc_middle::mir::ConstQualifs, diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 5c92f126e116c..83baf9584cb3c 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -7,6 +7,7 @@ use std::hash::Hash; use rustc_ast::tokenstream::TokenStream; use rustc_data_structures::stable_hasher::StableHash; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId}; +use rustc_hir::definitions::DisambiguatedDefPathData; use rustc_hir::hir_id::OwnerId; use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol}; @@ -360,3 +361,11 @@ impl<'tcx> QueryKey for (ty::Instance<'tcx>, CollectionMode) { self.0.default_span(tcx) } } + +impl QueryKey for (LocalDefId, DisambiguatedDefPathData) { + type Cache = DefaultCache; + + fn default_span(&self, _: TyCtxt<'_>) -> Span { + DUMMY_SP + } +} diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index a520e36a23d7e..6af92a36ea9ba 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -32,7 +32,9 @@ use rustc_data_structures::sync::{ use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, MultiSpan}; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, StableCrateIdMap}; -use rustc_hir::definitions::{DefPathData, Definitions, PerParentDisambiguatorState}; +use rustc_hir::definitions::{ + DefPathData, Definitions, DisambiguatedDefPathData, PerParentDisambiguatorState, +}; use rustc_hir::intravisit::VisitorExt; use rustc_hir::lang_items::LangItem; use rustc_hir::limit::Limit; @@ -52,7 +54,7 @@ use tracing::{debug, instrument}; use crate::arena::Arena; use crate::dep_graph::dep_node::make_metadata; -use crate::dep_graph::{DepGraph, DepKindVTable, DepNodeIndex}; +use crate::dep_graph::{DepGraph, DepKindVTable, TaskDepsRef}; use crate::ich::StableHashingContext; use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarKind}; use crate::lint::emit_lint_base; @@ -1281,6 +1283,23 @@ impl<'tcx> TyCtxt<'tcx> { } } +#[instrument(level = "trace", skip(tcx), ret)] +fn create_def_raw_provider<'tcx>( + tcx: TyCtxt<'tcx>, + (parent, data): (LocalDefId, DisambiguatedDefPathData), +) -> LocalDefId { + // The following call has the side effect of modifying the tables inside `definitions`. + // These very tables are relied on by the incr. comp. engine to decode DepNodes and to + // decode the on-disk cache. + // + // Any LocalDefId which is used within queries, either as key or result, either: + // - has been created before the construction of the TyCtxt; + // - has been created by this call to `create_def`. + // As a consequence, this LocalDefId is always re-created before it is needed by the incr. + // comp. engine itself. + tcx.untracked.definitions.write().create_def(parent, data) +} + impl<'tcx> TyCtxtAt<'tcx> { /// Create a new definition within the incr. comp. engine. pub fn create_def( @@ -1310,25 +1329,29 @@ impl<'tcx> TyCtxt<'tcx> { disambiguator: &mut PerParentDisambiguatorState, ) -> TyCtxtFeed<'tcx, LocalDefId> { let data = override_def_path_data.unwrap_or_else(|| def_kind.def_path_data(name)); - // The following call has the side effect of modifying the tables inside `definitions`. - // These very tables are relied on by the incr. comp. engine to decode DepNodes and to - // decode the on-disk cache. - // - // Any LocalDefId which is used within queries, either as key or result, either: - // - has been created before the construction of the TyCtxt; - // - has been created by this call to `create_def`. - // As a consequence, this LocalDefId is always re-created before it is needed by the incr. - // comp. engine itself. - let def_id = self.untracked.definitions.write().create_def(parent, data, disambiguator); - - // This function modifies `self.definitions` using a side-effect. - // We need to ensure that these side effects are re-run by the incr. comp. engine. - // Depending on the forever-red node will tell the graph that the calling query - // needs to be re-evaluated. - self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE); + + // Find the next free disambiguator for this key. + let data = disambiguator.disambiguate(parent, data); + + let def_id = ty::tls::with_context(|icx| match icx.task_deps { + // `create_def_raw` is a query, so it can be replayed by the dep-graph engine. + // However, we may invoke it multiple times with the same `(parent, data)` pair, + // and we expect to create *different* definitions from them. + // + // In order to make this compatible with the general model of queries, we add + // additional information which must change at each call. + TaskDepsRef::Allow(..) => self.create_def_raw((parent, data)), + + // If we are not tracking dependencies, we can use global mutable state. + // This is only an optimization to avoid the cost of registering the dep-node. + TaskDepsRef::EvalAlways | TaskDepsRef::Forbid | TaskDepsRef::Ignore => { + self.untracked.definitions.write().create_def(parent, data) + } + }); let feed = TyCtxtFeed { tcx: self, key: def_id }; feed.def_kind(def_kind); + // Unique types created for closures participate in type privacy checking. // They have visibilities inherited from the module they are defined in. // Visibilities for opaque types are meaningless, but still provided @@ -2761,4 +2784,5 @@ pub fn provide(providers: &mut Providers) { tcx.lang_items().panic_impl().is_some_and(|did| did.is_local()) }; providers.source_span = |tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP); + providers.create_def_raw = create_def_raw_provider; } From c005d92c50fd879b83142c9ee26e00033987d8d6 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Fri, 1 May 2026 15:07:37 +0000 Subject: [PATCH 03/15] Introduce QuerySideEffect::CreateDef. --- compiler/rustc_middle/src/dep_graph/graph.rs | 11 ++++++++++- compiler/rustc_middle/src/ty/context.rs | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/graph.rs b/compiler/rustc_middle/src/dep_graph/graph.rs index a219809541cc1..72f6782dffd1f 100644 --- a/compiler/rustc_middle/src/dep_graph/graph.rs +++ b/compiler/rustc_middle/src/dep_graph/graph.rs @@ -12,11 +12,13 @@ use rustc_data_structures::stable_hasher::{StableHash, StableHasher}; use rustc_data_structures::sync::{AtomicU64, Lock}; use rustc_data_structures::unord::UnordMap; use rustc_errors::DiagInner; +use rustc_hir::definitions::DisambiguatedDefPathData; use rustc_index::IndexVec; use rustc_macros::{Decodable, Encodable}; use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; use rustc_session::Session; use rustc_span::Symbol; +use rustc_span::def_id::LocalDefId; use tracing::instrument; #[cfg(debug_assertions)] use {super::debug::EdgeFilter, std::env}; @@ -50,6 +52,8 @@ pub enum QuerySideEffect { /// if we mark the query as green, as that query will have /// the side effect dep node as a dependency. CheckFeature { symbol: Symbol }, + /// Creates a new definition. + CreateDef { parent: LocalDefId, data: DisambiguatedDefPathData }, } #[derive(Clone)] @@ -533,7 +537,9 @@ impl DepGraph { side_effect: QuerySideEffect, ) -> DepNodeIndex { if let Some(ref data) = self.data { - data.encode_side_effect(tcx, side_effect) + let dep_node_index = data.encode_side_effect(tcx, side_effect); + self.read_index(dep_node_index); + dep_node_index } else { self.next_virtual_depnode_index() } @@ -725,6 +731,9 @@ impl DepGraphData { QuerySideEffect::CheckFeature { symbol } => { tcx.sess.used_features.lock().insert(*symbol, dep_node_index.as_u32()); } + QuerySideEffect::CreateDef { parent, data } => { + tcx.ensure_done().create_def_raw((*parent, *data)); + } } // This will just overwrite the same value for concurrent calls. diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 6af92a36ea9ba..55200f1660acd 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -54,7 +54,7 @@ use tracing::{debug, instrument}; use crate::arena::Arena; use crate::dep_graph::dep_node::make_metadata; -use crate::dep_graph::{DepGraph, DepKindVTable, TaskDepsRef}; +use crate::dep_graph::{DepGraph, DepKindVTable, QuerySideEffect, TaskDepsRef}; use crate::ich::StableHashingContext; use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarKind}; use crate::lint::emit_lint_base; @@ -1340,7 +1340,11 @@ impl<'tcx> TyCtxt<'tcx> { // // In order to make this compatible with the general model of queries, we add // additional information which must change at each call. - TaskDepsRef::Allow(..) => self.create_def_raw((parent, data)), + TaskDepsRef::Allow(..) => { + self.dep_graph + .encode_side_effect(self, QuerySideEffect::CreateDef { parent, data }); + self.create_def_raw((parent, data)) + } // If we are not tracking dependencies, we can use global mutable state. // This is only an optimization to avoid the cost of registering the dep-node. From 1a0280be8ac63bc4964626dd161c04cf56a3e4d8 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Fri, 1 May 2026 18:53:54 +0000 Subject: [PATCH 04/15] Move compute_stable_hash to DisambiguatedDefPathData. --- compiler/rustc_hir/src/definitions.rs | 49 +++++++++++++-------------- compiler/rustc_hir/src/tests.rs | 13 +++---- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index 6f757592aa6b0..80fdda5c46a89 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -166,16 +166,35 @@ pub struct DefKey { } impl DefKey { - pub(crate) fn compute_stable_hash(&self, parent: DefPathHash) -> DefPathHash { + #[inline] + pub fn get_opt_name(&self) -> Option { + self.disambiguated_data.data.get_opt_name() + } +} + +/// A pair of `DefPathData` and an integer disambiguator. The integer is +/// normally `0`, but in the event that there are multiple defs with the +/// same `parent` and `data`, we use this field to disambiguate +/// between them. This introduces some artificial ordering dependency +/// but means that if you have, e.g., two impls for the same type in +/// the same module, they do get distinct `DefId`s. +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Encodable, BlobDecodable, HashStable)] +pub struct DisambiguatedDefPathData { + pub data: DefPathData, + pub disambiguator: u32, +} + +impl DisambiguatedDefPathData { + pub fn compute_stable_hash(self, parent: DefPathHash) -> DefPathHash { let mut hasher = StableHasher::new(); // The new path is in the same crate as `parent`, and will contain the stable_crate_id. // Therefore, we only need to include information of the parent's local hash. parent.local_hash().hash(&mut hasher); - let DisambiguatedDefPathData { ref data, disambiguator } = self.disambiguated_data; + let DisambiguatedDefPathData { data, disambiguator } = self; - std::mem::discriminant(data).hash(&mut hasher); + std::mem::discriminant(&data).hash(&mut hasher); if let Some(name) = data.hashed_symbol() { // Get a stable hash by considering the symbol chars rather than // the symbol index. @@ -193,25 +212,6 @@ impl DefKey { DefPathHash::new(parent.stable_crate_id(), local_hash) } - #[inline] - pub fn get_opt_name(&self) -> Option { - self.disambiguated_data.data.get_opt_name() - } -} - -/// A pair of `DefPathData` and an integer disambiguator. The integer is -/// normally `0`, but in the event that there are multiple defs with the -/// same `parent` and `data`, we use this field to disambiguate -/// between them. This introduces some artificial ordering dependency -/// but means that if you have, e.g., two impls for the same type in -/// the same module, they do get distinct `DefId`s. -#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Encodable, BlobDecodable, HashStable)] -pub struct DisambiguatedDefPathData { - pub data: DefPathData, - pub disambiguator: u32, -} - -impl DisambiguatedDefPathData { pub fn as_sym(&self, verbose: bool) -> Symbol { match self.data.name() { DefPathDataName::Named(name) => { @@ -417,11 +417,10 @@ impl Definitions { // The root node must be created in `new()`. assert!(data.data != DefPathData::CrateRoot); - let key = DefKey { parent: Some(parent.local_def_index), disambiguated_data: data }; - let parent_hash = self.table.def_path_hash(parent.local_def_index); - let def_path_hash = key.compute_stable_hash(parent_hash); + let def_path_hash = data.compute_stable_hash(parent_hash); + let key = DefKey { parent: Some(parent.local_def_index), disambiguated_data: data }; debug!("create_def: after disambiguation, key = {:?}", key); // Create the definition. diff --git a/compiler/rustc_hir/src/tests.rs b/compiler/rustc_hir/src/tests.rs index 3b797c1f1038a..2aa5f7fd33bad 100644 --- a/compiler/rustc_hir/src/tests.rs +++ b/compiler/rustc_hir/src/tests.rs @@ -31,15 +31,10 @@ fn def_path_hash_depends_on_crate_id() { let parent_hash = DefPathHash::new(stable_crate_id, Hash64::new(stable_crate_id.as_u64())); - let key = DefKey { - parent: None, - disambiguated_data: DisambiguatedDefPathData { - data: DefPathData::CrateRoot, - disambiguator: 0, - }, - }; - - key.compute_stable_hash(parent_hash) + let disambiguated_data = + DisambiguatedDefPathData { data: DefPathData::CrateRoot, disambiguator: 0 }; + + disambiguated_data.compute_stable_hash(parent_hash) } }) } From 4455df973d196e70329a462aab73494c87c93191 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Fri, 1 May 2026 18:54:24 +0000 Subject: [PATCH 05/15] Introduce TaskDepsRef::Replay. --- compiler/rustc_interface/src/callbacks.rs | 5 ++++- compiler/rustc_middle/src/dep_graph/graph.rs | 16 +++++++++++++--- compiler/rustc_query_impl/src/execution.rs | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_interface/src/callbacks.rs b/compiler/rustc_interface/src/callbacks.rs index b2ad70bc4811b..fc54c871c3ed7 100644 --- a/compiler/rustc_interface/src/callbacks.rs +++ b/compiler/rustc_interface/src/callbacks.rs @@ -23,7 +23,10 @@ fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) { // Skip doing anything if we aren't tracking dependencies. let tracks_deps = match icx.task_deps { TaskDepsRef::Allow(..) => true, - TaskDepsRef::EvalAlways | TaskDepsRef::Ignore | TaskDepsRef::Forbid => false, + TaskDepsRef::EvalAlways + | TaskDepsRef::Ignore + | TaskDepsRef::Forbid + | TaskDepsRef::Replay => false, }; if tracks_deps { let _span = icx.tcx.source_span(def_id); diff --git a/compiler/rustc_middle/src/dep_graph/graph.rs b/compiler/rustc_middle/src/dep_graph/graph.rs index 72f6782dffd1f..745e1f2ae76ab 100644 --- a/compiler/rustc_middle/src/dep_graph/graph.rs +++ b/compiler/rustc_middle/src/dep_graph/graph.rs @@ -224,6 +224,13 @@ impl DepGraph { with_deps(TaskDepsRef::Ignore, op) } + pub fn with_replay(&self, op: OP) -> R + where + OP: FnOnce() -> R, + { + with_deps(TaskDepsRef::Replay, op) + } + /// Used to wrap the deserialization of a query result from disk, /// This method enforces that no new `DepNodes` are created during /// query result deserialization. @@ -462,7 +469,7 @@ impl DepGraph { // queries. They are re-evaluated unconditionally anyway. return; } - TaskDepsRef::Ignore => return, + TaskDepsRef::Ignore | TaskDepsRef::Replay => return, TaskDepsRef::Forbid => { // Reading is forbidden in this context. ICE with a useful error message. panic_on_forbidden_read(data, dep_node_index) @@ -512,7 +519,7 @@ impl DepGraph { pub fn record_diagnostic<'tcx>(&self, tcx: TyCtxt<'tcx>, diagnostic: &DiagInner) { if let Some(ref data) = self.data { read_deps(|task_deps| match task_deps { - TaskDepsRef::EvalAlways | TaskDepsRef::Ignore => return, + TaskDepsRef::EvalAlways | TaskDepsRef::Ignore | TaskDepsRef::Replay => return, TaskDepsRef::Forbid | TaskDepsRef::Allow(..) => { let dep_node_index = data .encode_side_effect(tcx, QuerySideEffect::Diagnostic(diagnostic.clone())); @@ -606,7 +613,7 @@ impl DepGraph { TaskDepsRef::EvalAlways => { edges.push(DepNodeIndex::FOREVER_RED_NODE); } - TaskDepsRef::Ignore => {} + TaskDepsRef::Ignore | TaskDepsRef::Replay => {} TaskDepsRef::Forbid => { panic!("Cannot summarize when dependencies are not recorded.") } @@ -1220,6 +1227,9 @@ pub enum TaskDepsRef<'a> { EvalAlways, /// New dependencies are ignored. This is also used for `dep_graph.with_ignore`. Ignore, + /// This query has already been marked green, its dependency graph is recorded, + /// but we need to re-run the code to get its result. + Replay, /// Any attempt to add new dependencies will cause a panic. /// This is used when decoding a query result from disk, /// to ensure that the decoding process doesn't itself diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index ed9ad8c7a0a68..8ef937948e3dc 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -529,7 +529,7 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>( // We could not load a result from the on-disk cache, so recompute. The dep-graph for // this computation is already in-place, so we can just call the query provider. let prof_timer = tcx.prof.query_provider(); - let value = tcx.dep_graph.with_ignore(|| (query.invoke_provider_fn)(tcx, key)); + let value = tcx.dep_graph.with_replay(|| (query.invoke_provider_fn)(tcx, key)); prof_timer.finish_with_query_invocation_id(dep_node_index.into()); (value, true) From 533f0dfb7576e2057e0db37e78326d37eefa0135 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Fri, 1 May 2026 18:55:03 +0000 Subject: [PATCH 06/15] Drop the create_def_raw query. --- compiler/rustc_hir/src/definitions.rs | 6 +-- compiler/rustc_middle/src/dep_graph/graph.rs | 2 +- compiler/rustc_middle/src/queries.rs | 12 ----- compiler/rustc_middle/src/query/keys.rs | 9 ---- compiler/rustc_middle/src/ty/context.rs | 50 +++++++------------- 5 files changed, 22 insertions(+), 57 deletions(-) diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index 80fdda5c46a89..55f739ba38a5f 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::StableHasher; use rustc_hashes::Hash64; use rustc_index::IndexVec; -use rustc_macros::{BlobDecodable, Decodable, Encodable, HashStable, extension}; +use rustc_macros::{BlobDecodable, Decodable, Encodable, extension}; use rustc_span::def_id::LocalDefIdMap; use rustc_span::{Symbol, kw, sym}; use tracing::{debug, instrument}; @@ -178,7 +178,7 @@ impl DefKey { /// between them. This introduces some artificial ordering dependency /// but means that if you have, e.g., two impls for the same type in /// the same module, they do get distinct `DefId`s. -#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Encodable, BlobDecodable, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Encodable, BlobDecodable)] pub struct DisambiguatedDefPathData { pub data: DefPathData, pub disambiguator: u32, @@ -299,7 +299,7 @@ impl DefPath { } /// New variants should only be added in synchronization with `enum DefKind`. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, BlobDecodable, HashStable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, BlobDecodable)] pub enum DefPathData { // Root: these should only be used for the root nodes, because // they are treated specially by the `def_path` function. diff --git a/compiler/rustc_middle/src/dep_graph/graph.rs b/compiler/rustc_middle/src/dep_graph/graph.rs index 745e1f2ae76ab..7b5d12791a60e 100644 --- a/compiler/rustc_middle/src/dep_graph/graph.rs +++ b/compiler/rustc_middle/src/dep_graph/graph.rs @@ -739,7 +739,7 @@ impl DepGraphData { tcx.sess.used_features.lock().insert(*symbol, dep_node_index.as_u32()); } QuerySideEffect::CreateDef { parent, data } => { - tcx.ensure_done().create_def_raw((*parent, *data)); + tcx.untracked().definitions.write().create_def(*parent, *data); } } diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index e572f7d236816..f0c367beefd65 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -67,7 +67,6 @@ use rustc_hir::def::{DefKind, DocLinkResMap}; use rustc_hir::def_id::{ CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap, LocalDefIdSet, LocalModDefId, }; -use rustc_hir::definitions::DisambiguatedDefPathData; use rustc_hir::lang_items::{LangItem, LanguageItems}; use rustc_hir::{ItemLocalId, ItemLocalMap, PreciseCapturingArgKind, TraitCandidate}; use rustc_index::IndexVec; @@ -199,17 +198,6 @@ rustc_queries! { desc { "getting the source span" } } - /// Create a new definition. - /// - /// This query is meant to wrap a side-effect and return the resulting newly created - /// definition. In incremental mode, when replaying a query, this query caches the side-effect - /// to avoid performing it twice. - query create_def_raw(key: (LocalDefId, DisambiguatedDefPathData)) -> LocalDefId { - // Accesses untracked data - eval_always - desc { "create a new definition for `{}::{:?}`", tcx.def_path_str(key.0), key.1 } - } - /// Represents crate as a whole (as distinct from the top-level crate module). /// /// If you call `tcx.hir_crate(())` we will have to assume that any change diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 83baf9584cb3c..5c92f126e116c 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -7,7 +7,6 @@ use std::hash::Hash; use rustc_ast::tokenstream::TokenStream; use rustc_data_structures::stable_hasher::StableHash; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId}; -use rustc_hir::definitions::DisambiguatedDefPathData; use rustc_hir::hir_id::OwnerId; use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol}; @@ -361,11 +360,3 @@ impl<'tcx> QueryKey for (ty::Instance<'tcx>, CollectionMode) { self.0.default_span(tcx) } } - -impl QueryKey for (LocalDefId, DisambiguatedDefPathData) { - type Cache = DefaultCache; - - fn default_span(&self, _: TyCtxt<'_>) -> Span { - DUMMY_SP - } -} diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 55200f1660acd..6cc991d505c79 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -32,9 +32,7 @@ use rustc_data_structures::sync::{ use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, MultiSpan}; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, StableCrateIdMap}; -use rustc_hir::definitions::{ - DefPathData, Definitions, DisambiguatedDefPathData, PerParentDisambiguatorState, -}; +use rustc_hir::definitions::{DefPathData, Definitions, PerParentDisambiguatorState}; use rustc_hir::intravisit::VisitorExt; use rustc_hir::lang_items::LangItem; use rustc_hir::limit::Limit; @@ -1283,23 +1281,6 @@ impl<'tcx> TyCtxt<'tcx> { } } -#[instrument(level = "trace", skip(tcx), ret)] -fn create_def_raw_provider<'tcx>( - tcx: TyCtxt<'tcx>, - (parent, data): (LocalDefId, DisambiguatedDefPathData), -) -> LocalDefId { - // The following call has the side effect of modifying the tables inside `definitions`. - // These very tables are relied on by the incr. comp. engine to decode DepNodes and to - // decode the on-disk cache. - // - // Any LocalDefId which is used within queries, either as key or result, either: - // - has been created before the construction of the TyCtxt; - // - has been created by this call to `create_def`. - // As a consequence, this LocalDefId is always re-created before it is needed by the incr. - // comp. engine itself. - tcx.untracked.definitions.write().create_def(parent, data) -} - impl<'tcx> TyCtxtAt<'tcx> { /// Create a new definition within the incr. comp. engine. pub fn create_def( @@ -1334,22 +1315,28 @@ impl<'tcx> TyCtxt<'tcx> { let data = disambiguator.disambiguate(parent, data); let def_id = ty::tls::with_context(|icx| match icx.task_deps { - // `create_def_raw` is a query, so it can be replayed by the dep-graph engine. - // However, we may invoke it multiple times with the same `(parent, data)` pair, - // and we expect to create *different* definitions from them. - // - // In order to make this compatible with the general model of queries, we add - // additional information which must change at each call. + // If we are not tracking dependencies, we can use global mutable state. + // This is only an optimization to avoid the cost of registering the dep-node. + TaskDepsRef::EvalAlways | TaskDepsRef::Forbid | TaskDepsRef::Ignore => { + self.untracked.definitions.write().create_def(parent, data) + } + + // We are tracking dependencies, so we need to record a side-effect for the dep-graph + // to pick up in next execution. TaskDepsRef::Allow(..) => { self.dep_graph .encode_side_effect(self, QuerySideEffect::CreateDef { parent, data }); - self.create_def_raw((parent, data)) + self.untracked.definitions.write().create_def(parent, data) } - // If we are not tracking dependencies, we can use global mutable state. - // This is only an optimization to avoid the cost of registering the dep-node. - TaskDepsRef::EvalAlways | TaskDepsRef::Forbid | TaskDepsRef::Ignore => { - self.untracked.definitions.write().create_def(parent, data) + // We are in replay mode: the def-id has already been created by + // `dep_graph.force_side_effect`. We need to recover it, without creating a new one. + TaskDepsRef::Replay => { + let parent_hash = self.def_path_hash(parent.to_def_id()); + let def_path_hash = data.compute_stable_hash(parent_hash); + self.def_path_hash_to_def_id(def_path_hash) + .expect("first execution should have created this definition") + .expect_local() } }); @@ -2788,5 +2775,4 @@ pub fn provide(providers: &mut Providers) { tcx.lang_items().panic_impl().is_some_and(|did| did.is_local()) }; providers.source_span = |tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP); - providers.create_def_raw = create_def_raw_provider; } From a758fe65bb58ad58a3e04aacab4af86f7c60fa3d Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Sun, 26 Apr 2026 03:18:42 +0000 Subject: [PATCH 07/15] Introduce DefKind::Promoted. --- compiler/rustc_hir/src/def.rs | 12 +++++++++++- compiler/rustc_hir/src/definitions.rs | 5 +++++ compiler/rustc_hir_analysis/src/check/wfcheck.rs | 1 + .../rustc_hir_analysis/src/hir_ty_lowering/mod.rs | 1 + compiler/rustc_metadata/src/rmeta/encoder.rs | 14 +++++++++++++- compiler/rustc_metadata/src/rmeta/table.rs | 1 + compiler/rustc_middle/src/ty/context.rs | 1 + compiler/rustc_middle/src/ty/mod.rs | 1 + compiler/rustc_middle/src/ty/print/mod.rs | 2 ++ compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- compiler/rustc_middle/src/ty/sty.rs | 1 + compiler/rustc_passes/src/dead.rs | 1 + compiler/rustc_privacy/src/lib.rs | 2 ++ compiler/rustc_public/src/unstable/mod.rs | 3 ++- compiler/rustc_resolve/src/build_reduced_graph.rs | 1 + .../src/cfi/typeid/itanium_cxx_abi/encode.rs | 1 + compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_symbol_mangling/src/v0.rs | 1 + compiler/rustc_ty_utils/src/implied_bounds.rs | 1 + compiler/rustc_ty_utils/src/opaque_types.rs | 5 ++++- compiler/rustc_ty_utils/src/sig_types.rs | 2 +- src/librustdoc/formats/item_type.rs | 1 + src/librustdoc/passes/collect_intra_doc_links.rs | 1 + .../clippy_lints/src/manual_float_methods.rs | 1 + 24 files changed, 56 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index f268192233c0d..652b8e83940a3 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -197,6 +197,8 @@ pub enum DefKind { /// The definition of a synthetic coroutine body created by the lowering of a /// coroutine-closure, such as an async closure. SyntheticCoroutineBody, + /// Promoted constant from a MIR body. + Promoted, } impl DefKind { @@ -242,6 +244,7 @@ impl DefKind { DefKind::ExternCrate => "extern crate", DefKind::GlobalAsm => "global assembly block", DefKind::SyntheticCoroutineBody => "synthetic mir body", + DefKind::Promoted => "promoted constant", } } @@ -293,6 +296,7 @@ impl DefKind { // Not namespaced. DefKind::AnonConst | DefKind::InlineConst + | DefKind::Promoted | DefKind::Field | DefKind::LifetimeParam | DefKind::ExternCrate @@ -345,6 +349,7 @@ impl DefKind { DefKind::Impl { .. } => DefPathData::Impl, DefKind::Closure => DefPathData::Closure, DefKind::SyntheticCoroutineBody => DefPathData::SyntheticCoroutineBody, + DefKind::Promoted => DefPathData::Promoted, } } @@ -391,6 +396,7 @@ impl DefKind { | DefKind::Static { .. } | DefKind::Struct | DefKind::SyntheticCoroutineBody + | DefKind::Promoted | DefKind::Trait | DefKind::TraitAlias | DefKind::TyAlias @@ -441,6 +447,7 @@ impl DefKind { | DefKind::AnonConst | DefKind::InlineConst | DefKind::GlobalAsm + | DefKind::Promoted | DefKind::ExternCrate => false, } } @@ -450,7 +457,10 @@ impl DefKind { #[inline] pub fn is_typeck_child(self) -> bool { match self { - DefKind::Closure | DefKind::InlineConst | DefKind::SyntheticCoroutineBody => true, + DefKind::Closure + | DefKind::InlineConst + | DefKind::SyntheticCoroutineBody + | DefKind::Promoted => true, DefKind::Mod | DefKind::Struct | DefKind::Union diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index 55f739ba38a5f..3d2cd25cf233d 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -331,6 +331,8 @@ pub enum DefPathData { Ctor, /// A constant expression (see `{ast,hir}::AnonConst`). AnonConst, + /// A constant promoted from a MIR body. + Promoted, /// An existential `impl Trait` type node. /// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name. OpaqueTy, @@ -474,6 +476,7 @@ impl DefPathData { | OpaqueTy | AnonAssocTy(..) | SyntheticCoroutineBody + | Promoted | NestedStatic => None, } } @@ -494,6 +497,7 @@ impl DefPathData { | AnonConst | OpaqueTy | SyntheticCoroutineBody + | Promoted | NestedStatic => None, } } @@ -516,6 +520,7 @@ impl DefPathData { AnonAssocTy(..) => DefPathDataName::Anon { namespace: sym::anon_assoc }, SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic }, NestedStatic => DefPathDataName::Anon { namespace: sym::nested }, + Promoted => DefPathDataName::Anon { namespace: sym::promoted }, } } } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index c9b1bcf52f574..e62df98403fdc 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -2496,6 +2496,7 @@ fn lint_redundant_lifetimes<'tcx>( | DefKind::LifetimeParam | DefKind::GlobalAsm | DefKind::Closure + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => return, } diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 473a32bac03a9..b04a99eddd11f 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2947,6 +2947,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | DefKind::Closure | DefKind::ExternCrate | DefKind::GlobalAsm + | DefKind::Promoted | DefKind::SyntheticCoroutineBody, _, ) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index c77711354f459..58c7f88c08872 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -912,6 +912,7 @@ fn should_encode_span(def_kind: DefKind) -> bool { | DefKind::AssocConst { .. } | DefKind::Macro(_) | DefKind::ExternCrate + | DefKind::Promoted | DefKind::Use | DefKind::AnonConst | DefKind::InlineConst @@ -961,6 +962,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool { | DefKind::ForeignMod | DefKind::AnonConst | DefKind::InlineConst + | DefKind::Promoted | DefKind::OpaqueTy | DefKind::LifetimeParam | DefKind::Static { nested: true, .. } @@ -998,6 +1000,7 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool { | DefKind::OpaqueTy | DefKind::Field | DefKind::LifetimeParam + | DefKind::Promoted | DefKind::GlobalAsm | DefKind::Closure | DefKind::SyntheticCoroutineBody => false, @@ -1037,6 +1040,7 @@ fn should_encode_visibility(def_kind: DefKind) -> bool { | DefKind::Impl { .. } | DefKind::Closure | DefKind::ExternCrate + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => false, } } @@ -1073,6 +1077,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool { | DefKind::GlobalAsm | DefKind::Closure | DefKind::ExternCrate + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => false, } } @@ -1109,7 +1114,8 @@ fn should_encode_mir( DefKind::AnonConst { .. } | DefKind::InlineConst | DefKind::AssocConst { .. } - | DefKind::Const { .. } => (true, false), + | DefKind::Const { .. } + | DefKind::Promoted => (true, false), // Coroutines require optimized MIR to compute layout. DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true), DefKind::SyntheticCoroutineBody => (false, true), @@ -1163,6 +1169,7 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def | DefKind::GlobalAsm | DefKind::Closure | DefKind::ExternCrate + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => false, DefKind::TyAlias => tcx.type_alias_is_lazy(def_id), } @@ -1192,6 +1199,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool { | DefKind::Field | DefKind::TyParam | DefKind::Closure + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => true, DefKind::Mod | DefKind::ForeignMod @@ -1224,6 +1232,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) -> | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => true, DefKind::OpaqueTy => { @@ -1286,6 +1295,7 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool { | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst + | DefKind::Promoted | DefKind::AssocTy | DefKind::TyParam | DefKind::Trait @@ -1323,6 +1333,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool { | DefKind::ForeignTy | DefKind::ConstParam | DefKind::InlineConst + | DefKind::Promoted | DefKind::AssocTy | DefKind::TyParam | DefKind::Trait @@ -1374,6 +1385,7 @@ fn should_encode_const(def_kind: DefKind) -> bool { | DefKind::LifetimeParam | DefKind::GlobalAsm | DefKind::ExternCrate + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => false, } } diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs index 26c5908563777..e8e0138c10c67 100644 --- a/compiler/rustc_metadata/src/rmeta/table.rs +++ b/compiler/rustc_metadata/src/rmeta/table.rs @@ -183,6 +183,7 @@ fixed_size_enum! { ( Impl { of_trait: false } ) ( Impl { of_trait: true } ) ( Closure ) + ( Promoted ) ( Static { safety: hir::Safety::Unsafe, mutability: ast::Mutability::Not, nested: false } ) ( Static { safety: hir::Safety::Safe, mutability: ast::Mutability::Not, nested: false } ) ( Static { safety: hir::Safety::Unsafe, mutability: ast::Mutability::Mut, nested: false } ) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 6cc991d505c79..b5c1033700246 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -838,6 +838,7 @@ impl<'tcx> TyCtxt<'tcx> { | DefKind::Const { .. } | DefKind::InlineConst | DefKind::GlobalAsm + | DefKind::Promoted ) { CodegenFnAttrs::EMPTY } else { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index df62e566032a5..9b87b1b1dcf5c 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2157,6 +2157,7 @@ impl<'tcx> TyCtxt<'tcx> { | DefKind::Field | DefKind::LifetimeParam | DefKind::GlobalAsm + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => false, } } diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index d5d1c3634c7d1..057249e80422a 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -197,6 +197,8 @@ pub trait Printer<'tcx>: Sized { // Anon consts doesn't have their own generics, and inline consts' own // generics are their inferred types, so don't print them. DefPathData::AnonConst => {} + // Promoted do not have their own generics, so we don't print them. + DefPathData::Promoted => {} // If we have any generic arguments to print, we do that // on top of the same path, but without its own generics. diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 04d76e4304fe9..f616a104c6c62 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1566,7 +1566,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { DefKind::Const { .. } | DefKind::AssocConst { .. } => { self.pretty_print_value_path(def, args)?; } - DefKind::AnonConst => { + DefKind::AnonConst | DefKind::Promoted => { if def.is_local() && let span = self.tcx().def_span(def) && let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 5360a123a4199..c378cef16818f 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -662,6 +662,7 @@ impl<'tcx> Ty<'tcx> { | DefKind::GlobalAsm | DefKind::Impl { .. } | DefKind::Closure + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => { bug!("not an adt: {def:?} ({:?})", tcx.def_kind(def.did())) } diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 7eb484b1d57a7..d763ffe5c53c8 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -63,6 +63,7 @@ fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { | DefKind::Field | DefKind::LifetimeParam | DefKind::Closure + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => false, } } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index ba30dfccc33cc..c9420b3577165 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -659,6 +659,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { | DefKind::InlineConst | DefKind::Field | DefKind::GlobalAsm + | DefKind::Promoted | DefKind::Impl { .. } | DefKind::Closure | DefKind::SyntheticCoroutineBody => (), @@ -828,6 +829,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { | DefKind::SyntheticCoroutineBody | DefKind::ConstParam | DefKind::LifetimeParam + | DefKind::Promoted | DefKind::Ctor(..) => { bug!("should be checked while checking parent") } diff --git a/compiler/rustc_public/src/unstable/mod.rs b/compiler/rustc_public/src/unstable/mod.rs index 8c20a54018553..365926c8bd020 100644 --- a/compiler/rustc_public/src/unstable/mod.rs +++ b/compiler/rustc_public/src/unstable/mod.rs @@ -129,7 +129,8 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind { DefKind::Const { .. } | DefKind::InlineConst | DefKind::AssocConst { .. } - | DefKind::AnonConst => ItemKind::Const, + | DefKind::AnonConst + | DefKind::Promoted => ItemKind::Const, DefKind::Static { .. } => ItemKind::Static, DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const), DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn), diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 4c307e8a6a3d7..dc94ba8fbbbe9 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -444,6 +444,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | DefKind::GlobalAsm | DefKind::Closure | DefKind::SyntheticCoroutineBody + | DefKind::Promoted | DefKind::Impl { .. }, _, ) diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs index 873ed9bb10398..6be874a01dab6 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs @@ -684,6 +684,7 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String { hir::definitions::DefPathData::Closure => "C", hir::definitions::DefPathData::Ctor => "c", hir::definitions::DefPathData::AnonConst => "K", + hir::definitions::DefPathData::Promoted => "p", hir::definitions::DefPathData::OpaqueTy => "i", hir::definitions::DefPathData::SyntheticCoroutineBody => "s", hir::definitions::DefPathData::NestedStatic => "n", diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index d4888a6949653..ecd0289336eb7 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1569,6 +1569,7 @@ symbols! { proc_macro_non_items, proc_macro_path_invoc, profiler_runtime, + promoted, ptr, ptr_cast, ptr_cast_const, diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 46a7e092e6bc9..fd9d752dbaaa3 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -897,6 +897,7 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> { DefPathData::Closure => 'C', DefPathData::Ctor => 'c', DefPathData::AnonConst => 'K', + DefPathData::Promoted => 'p', DefPathData::OpaqueTy => 'i', DefPathData::SyntheticCoroutineBody => 's', DefPathData::NestedStatic => 'n', diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 659229a58d539..18ec0b370f7ac 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -152,6 +152,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' | DefKind::LifetimeParam | DefKind::GlobalAsm | DefKind::Closure + | DefKind::Promoted | DefKind::SyntheticCoroutineBody => { span_bug!( tcx.def_span(def_id), diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index e5de396c1cbdd..c8d9596a0ec0d 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -335,7 +335,10 @@ fn opaque_types_defined_by<'tcx>( // Note that we also support `SyntheticCoroutineBody` since we create // a MIR body for the def kind, and some MIR passes (like promotion) // may require doing analysis using its typing env. - DefKind::Closure | DefKind::InlineConst | DefKind::SyntheticCoroutineBody => { + DefKind::Closure + | DefKind::InlineConst + | DefKind::SyntheticCoroutineBody + | DefKind::Promoted => { collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item))); } DefKind::AssocTy | DefKind::TyAlias | DefKind::GlobalAsm => {} diff --git a/compiler/rustc_ty_utils/src/sig_types.rs b/compiler/rustc_ty_utils/src/sig_types.rs index ab4bfd998cf34..696843695109e 100644 --- a/compiler/rustc_ty_utils/src/sig_types.rs +++ b/compiler/rustc_ty_utils/src/sig_types.rs @@ -84,7 +84,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( // These are not part of a public API, they can only appear as hidden types, and there // the interesting parts are solely in the signature of the containing item's opaque type // or dyn type. - DefKind::InlineConst | DefKind::Closure | DefKind::SyntheticCoroutineBody => {} + DefKind::InlineConst | DefKind::Closure | DefKind::SyntheticCoroutineBody | DefKind::Promoted => {} DefKind::Impl { of_trait } => { if of_trait { let span = tcx.hir_node_by_def_id(item).expect_item().expect_impl().of_trait.unwrap().trait_ref.path.span; diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs index eb3492e4625be..a17449c1e6e40 100644 --- a/src/librustdoc/formats/item_type.rs +++ b/src/librustdoc/formats/item_type.rs @@ -188,6 +188,7 @@ impl ItemType { | DefKind::ForeignMod | DefKind::AnonConst | DefKind::InlineConst + | DefKind::Promoted | DefKind::OpaqueTy | DefKind::LifetimeParam | DefKind::GlobalAsm diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index eb1dee2e16d7b..b15696b1fd3b6 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -2166,6 +2166,7 @@ fn resolution_failure( | LifetimeParam | Ctor(_, _) | AnonConst + | Promoted | InlineConst => { let note = assoc_item_not_allowed(res); if let Some(span) = sp { diff --git a/src/tools/clippy/clippy_lints/src/manual_float_methods.rs b/src/tools/clippy/clippy_lints/src/manual_float_methods.rs index 4a2784caf4c74..a69821892387d 100644 --- a/src/tools/clippy/clippy_lints/src/manual_float_methods.rs +++ b/src/tools/clippy/clippy_lints/src/manual_float_methods.rs @@ -127,6 +127,7 @@ fn is_not_const(tcx: TyCtxt<'_>, def_id: DefId) -> bool { | DefKind::ConstParam | DefKind::Static { .. } | DefKind::Ctor(..) + | DefKind::Promoted | DefKind::AssocConst { .. } => false, DefKind::Fn | DefKind::AssocFn | DefKind::Closure => tcx.constness(def_id) == Constness::NotConst, From f5b8fea84a9147bc880288e8b307dc322d57dd28 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Sun, 26 Apr 2026 04:19:07 +0000 Subject: [PATCH 08/15] Create definitions for promoted constants. --- compiler/rustc_borrowck/src/consumers.rs | 5 +- compiler/rustc_borrowck/src/lib.rs | 61 +----- compiler/rustc_borrowck/src/nll.rs | 8 +- .../rustc_borrowck/src/region_infer/values.rs | 76 +------ compiler/rustc_borrowck/src/renumber.rs | 20 +- compiler/rustc_borrowck/src/root_cx.rs | 8 + compiler/rustc_borrowck/src/type_check/mod.rs | 135 ++---------- .../rustc_borrowck/src/universal_regions.rs | 2 +- .../src/check_consts/qualifs.rs | 11 +- .../src/const_eval/eval_queries.rs | 48 ++-- .../src/interpret/eval_context.rs | 7 +- .../src/collect/generics_of.rs | 35 ++- .../rustc_hir_analysis/src/collect/type_of.rs | 9 +- .../rustc_incremental/src/persist/clean.rs | 2 +- compiler/rustc_interface/src/passes.rs | 12 +- .../src/rmeta/decoder/cstore_impl.rs | 1 - compiler/rustc_metadata/src/rmeta/encoder.rs | 7 - compiler/rustc_metadata/src/rmeta/mod.rs | 1 - compiler/rustc_middle/src/arena.rs | 4 +- compiler/rustc_middle/src/hir/map.rs | 3 +- compiler/rustc_middle/src/mir/pretty.rs | 41 ++-- compiler/rustc_middle/src/mir/visit.rs | 20 +- compiler/rustc_middle/src/queries.rs | 25 +-- .../rustc_middle/src/query/on_disk_cache.rs | 5 +- compiler/rustc_middle/src/ty/context.rs | 13 +- compiler/rustc_middle/src/ty/instance.rs | 1 + compiler/rustc_middle/src/ty/mod.rs | 1 + .../src/known_panics_lint.rs | 15 +- compiler/rustc_mir_transform/src/lib.rs | 35 ++- .../rustc_mir_transform/src/promote_consts.rs | 206 +++++++++++------- compiler/rustc_ty_utils/src/ty.rs | 4 + 31 files changed, 326 insertions(+), 495 deletions(-) diff --git a/compiler/rustc_borrowck/src/consumers.rs b/compiler/rustc_borrowck/src/consumers.rs index 548973714105b..96c2c79e3b469 100644 --- a/compiler/rustc_borrowck/src/consumers.rs +++ b/compiler/rustc_borrowck/src/consumers.rs @@ -2,9 +2,8 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::LocalDefId; -use rustc_index::IndexVec; use rustc_middle::bug; -use rustc_middle::mir::{Body, Promoted}; +use rustc_middle::mir::Body; use rustc_middle::ty::TyCtxt; pub use super::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation}; @@ -85,8 +84,6 @@ pub enum ConsumerOptions { pub struct BodyWithBorrowckFacts<'tcx> { /// A mir body that contains region identifiers. pub body: Body<'tcx>, - /// The mir bodies of promoteds. - pub promoted: IndexVec>, /// The set of borrows occurring in `body` with data about them. pub borrow_set: BorrowSet<'tcx>, /// Context generated during borrowck, intended to be passed to diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 822fe1e58ebba..a80ac74849909 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -28,8 +28,8 @@ use rustc_data_structures::graph::dominators::Dominators; use rustc_hir as hir; use rustc_hir::CRATE_HIR_ID; use rustc_hir::def_id::LocalDefId; +use rustc_index::IndexVec; use rustc_index::bit_set::MixedBitSet; -use rustc_index::{IndexSlice, IndexVec}; use rustc_infer::infer::outlives::env::RegionBoundPairs; use rustc_infer::infer::{ InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt, @@ -289,7 +289,6 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> { struct CollectRegionConstraintsResult<'tcx> { infcx: BorrowckInferCtxt<'tcx>, body_owned: Body<'tcx>, - promoted: IndexVec>, move_data: MoveData<'tcx>, borrow_set: BorrowSet<'tcx>, location_table: PoloniusLocationTable, @@ -313,9 +312,8 @@ fn borrowck_collect_region_constraints<'tcx>( ) -> CollectRegionConstraintsResult<'tcx> { let tcx = root_cx.tcx; let infcx = BorrowckInferCtxt::new(tcx, def, root_cx.root_def_id()); - let (input_body, promoted) = tcx.mir_promoted(def); + let (input_body, _) = tcx.mir_promoted(def); let input_body: &Body<'_> = &input_body.borrow(); - let input_promoted: &IndexSlice<_, _> = &promoted.borrow(); if let Some(e) = input_body.tainted_by_errors { infcx.set_tainted_by_errors(e); root_cx.set_tainted_by_errors(e); @@ -326,8 +324,7 @@ fn borrowck_collect_region_constraints<'tcx>( // be modified (in place) to contain non-lexical lifetimes. It // will have a lifetime tied to the inference context. let mut body_owned = input_body.clone(); - let mut promoted = input_promoted.to_owned(); - let universal_regions = nll::replace_regions_in_mir(&infcx, &mut body_owned, &mut promoted); + let universal_regions = nll::replace_regions_in_mir(&infcx, &mut body_owned); let body = &body_owned; // no further changes let location_table = PoloniusLocationTable::new(body); @@ -356,7 +353,6 @@ fn borrowck_collect_region_constraints<'tcx>( root_cx, &infcx, body, - &promoted, universal_regions, &location_table, &borrow_set, @@ -368,7 +364,6 @@ fn borrowck_collect_region_constraints<'tcx>( CollectRegionConstraintsResult { infcx, body_owned, - promoted, move_data, borrow_set, location_table, @@ -392,7 +387,6 @@ fn borrowck_check_region_constraints<'tcx>( CollectRegionConstraintsResult { infcx, body_owned, - promoted, move_data, borrow_set, location_table, @@ -456,54 +450,6 @@ fn borrowck_check_region_constraints<'tcx>( && tcx.coroutine_movability(def.to_def_id()) == hir::Movability::Movable; let diags_buffer = &mut BorrowckDiagnosticsBuffer::default(); - // While promoteds should mostly be correct by construction, we need to check them for - // invalid moves to detect moving out of arrays:`struct S; fn main() { &([S][0]); }`. - for promoted_body in &promoted { - use rustc_middle::mir::visit::Visitor; - // This assumes that we won't use some of the fields of the `promoted_mbcx` - // when detecting and reporting move errors. While it would be nice to move - // this check out of `MirBorrowckCtxt`, actually doing so is far from trivial. - let move_data = MoveData::gather_moves(promoted_body, tcx, |_| true); - let mut promoted_mbcx = MirBorrowckCtxt { - root_cx, - infcx: &infcx, - body: promoted_body, - move_data: &move_data, - // no need to create a real location table for the promoted, it is not used - location_table: &location_table, - movable_coroutine, - fn_self_span_reported: Default::default(), - access_place_error_reported: Default::default(), - reservation_error_reported: Default::default(), - uninitialized_error_reported: Default::default(), - regioncx: ®ioncx, - used_mut: Default::default(), - used_mut_upvars: SmallVec::new(), - borrow_set: &borrow_set, - upvars: &[], - local_names: OnceCell::from(IndexVec::from_elem(None, &promoted_body.local_decls)), - region_names: RefCell::default(), - next_region_name: RefCell::new(1), - polonius_output: None, - move_errors: Vec::new(), - diags_buffer, - polonius_context: polonius_context.as_ref(), - }; - struct MoveVisitor<'a, 'b, 'infcx, 'tcx> { - ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>, - } - - impl<'tcx> Visitor<'tcx> for MoveVisitor<'_, '_, '_, 'tcx> { - fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) { - if let Operand::Move(place) = operand { - self.ctxt.check_movable_place(location, *place); - } - } - } - MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body); - promoted_mbcx.report_move_errors(); - } - let mut mbcx = MirBorrowckCtxt { root_cx, infcx: &infcx, @@ -580,7 +526,6 @@ fn borrowck_check_region_constraints<'tcx>( def, BodyWithBorrowckFacts { body: body_owned, - promoted, borrow_set, region_inference_context: regioncx, location_table: polonius_input.as_ref().map(|_| location_table), diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index dd6eb17947577..b0ccec8c9402f 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -8,9 +8,8 @@ use std::str::FromStr; use polonius_engine::{Algorithm, AllFacts, Output}; use rustc_data_structures::frozen::Frozen; use rustc_hir::find_attr; -use rustc_index::IndexSlice; use rustc_middle::mir::pretty::PrettyPrintMirOptions; -use rustc_middle::mir::{Body, MirDumper, PassWhere, Promoted}; +use rustc_middle::mir::{Body, MirDumper, PassWhere}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, TyCtxt}; use rustc_mir_dataflow::move_paths::MoveData; @@ -52,11 +51,10 @@ pub(crate) struct NllOutput<'tcx> { /// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal /// regions (e.g., region parameters) declared on the function. That set will need to be given to /// `compute_regions`. -#[instrument(skip(infcx, body, promoted), level = "debug")] +#[instrument(skip(infcx, body), level = "debug")] pub(crate) fn replace_regions_in_mir<'tcx>( infcx: &BorrowckInferCtxt<'tcx>, body: &mut Body<'tcx>, - promoted: &mut IndexSlice>, ) -> UniversalRegions<'tcx> { let def = body.source.def_id().expect_local(); @@ -66,7 +64,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>( let universal_regions = UniversalRegions::new(infcx, def); // Replace all remaining regions with fresh inference variables. - renumber::renumber_mir(infcx, body, promoted); + renumber::renumber_mir(infcx, body); if let Some(dumper) = MirDumper::new(infcx.tcx, "renumber", body) { dumper.dump_mir(body); diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index 6a0d70790cfef..be17ebd636cd9 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -1,7 +1,7 @@ use std::fmt::Debug; use std::rc::Rc; -use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; +use rustc_data_structures::fx::FxIndexSet; use rustc_index::Idx; use rustc_index::bit_set::SparseBitMatrix; use rustc_index::interval::{IntervalSet, SparseIntervalMatrix}; @@ -42,15 +42,11 @@ pub(crate) struct LivenessValues { /// The map from locations to points. location_map: Rc, - /// Which regions are live. This is exclusive with the fine-grained tracking in `points`, and - /// currently only used for validating promoteds (which don't care about more precise tracking). - live_regions: Option>, - /// For each region: the points where it is live. /// /// This is not initialized for promoteds, because we don't care *where* within a promoted a /// region is live, only that it is. - points: Option>, + points: SparseIntervalMatrix, /// When using `-Zpolonius=next`, the set of loans that are live at a given point in the CFG. live_loans: Option, @@ -60,21 +56,7 @@ impl LivenessValues { /// Create an empty map of regions to locations where they're live. pub(crate) fn with_specific_points(location_map: Rc) -> Self { LivenessValues { - live_regions: None, - points: Some(SparseIntervalMatrix::new(location_map.num_points())), - location_map, - live_loans: None, - } - } - - /// Create an empty map of regions to locations where they're live. - /// - /// Unlike `with_specific_points`, does not track exact locations where something is live, only - /// which regions are live. - pub(crate) fn without_specific_points(location_map: Rc) -> Self { - LivenessValues { - live_regions: Some(Default::default()), - points: None, + points: SparseIntervalMatrix::new(location_map.num_points()), location_map, live_loans: None, } @@ -83,52 +65,30 @@ impl LivenessValues { /// Returns the liveness matrix of points where each region is live. Panics if the liveness /// values have been created without any per-point data (that is, for promoteds). pub(crate) fn points(&self) -> &SparseIntervalMatrix { - self.points - .as_ref() - .expect("this `LivenessValues` wasn't created using `with_specific_points`") + &self.points } /// Iterate through each region that has a value in this set. pub(crate) fn regions(&self) -> impl Iterator { - self.points.as_ref().expect("use with_specific_points").rows() - } - - /// Iterate through each region that has a value in this set. - // We are passing query instability implications to the caller. - #[rustc_lint_query_instability] - #[allow(rustc::potential_query_instability)] - pub(crate) fn live_regions_unordered(&self) -> impl Iterator { - self.live_regions.as_ref().unwrap().iter().copied() + self.points.rows() } /// Records `region` as being live at the given `location`. pub(crate) fn add_location(&mut self, region: RegionVid, location: Location) { let point = self.location_map.point_from_location(location); debug!("LivenessValues::add_location(region={:?}, location={:?})", region, location); - if let Some(points) = &mut self.points { - points.insert(region, point); - } else if self.location_map.point_in_range(point) { - self.live_regions.as_mut().unwrap().insert(region); - } + self.points.insert(region, point); } /// Records `region` as being live at all the given `points`. pub(crate) fn add_points(&mut self, region: RegionVid, points: &IntervalSet) { debug!("LivenessValues::add_points(region={:?}, points={:?})", region, points); - if let Some(this) = &mut self.points { - this.union_row(region, points); - } else if points.iter().any(|point| self.location_map.point_in_range(point)) { - self.live_regions.as_mut().unwrap().insert(region); - } + self.points.union_row(region, points); } /// Records `region` as being live at all the control-flow points. pub(crate) fn add_all_points(&mut self, region: RegionVid) { - if let Some(points) = &mut self.points { - points.insert_all_into_row(region); - } else { - self.live_regions.as_mut().unwrap().insert(region); - } + self.points.insert_all_into_row(region); } /// Returns whether `region` is marked live at the given @@ -142,23 +102,12 @@ impl LivenessValues { /// [`point`][rustc_mir_dataflow::points::PointIndex]. #[inline] pub(crate) fn is_live_at_point(&self, region: RegionVid, point: PointIndex) -> bool { - if let Some(points) = &self.points { - points.row(region).is_some_and(|r| r.contains(point)) - } else { - unreachable!( - "Should be using LivenessValues::with_specific_points to ask whether live at a location" - ) - } + self.points.row(region).is_some_and(|r| r.contains(point)) } /// Returns an iterator of all the points where `region` is live. fn live_points(&self, region: RegionVid) -> impl Iterator { - let Some(points) = &self.points else { - unreachable!( - "Should be using LivenessValues::with_specific_points to ask whether live at a location" - ) - }; - points + self.points .row(region) .into_iter() .flat_map(|set| set.iter()) @@ -328,10 +277,7 @@ impl<'tcx, N: Idx> RegionValues<'tcx, N> { /// elements for the region `from` from `values` and add them to /// the region `to` in `self`. pub(crate) fn merge_liveness(&mut self, to: N, from: RegionVid, values: &LivenessValues) { - let Some(value_points) = &values.points else { - panic!("LivenessValues must track specific points for use in merge_liveness"); - }; - if let Some(set) = value_points.row(from) { + if let Some(set) = values.points.row(from) { self.points.union_row(to, set); } } diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs index d6dbc7dd831fb..e528b77fe9fa8 100644 --- a/compiler/rustc_borrowck/src/renumber.rs +++ b/compiler/rustc_borrowck/src/renumber.rs @@ -1,7 +1,6 @@ -use rustc_index::IndexSlice; use rustc_infer::infer::NllRegionVariableOrigin; use rustc_middle::mir::visit::{MutVisitor, TyContext}; -use rustc_middle::mir::{Body, ConstOperand, Location, Promoted}; +use rustc_middle::mir::{Body, ConstOperand, Location}; use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, fold_regions}; use rustc_span::Symbol; use tracing::{debug, instrument}; @@ -10,21 +9,10 @@ use crate::BorrowckInferCtxt; /// Replaces all free regions appearing in the MIR with fresh /// inference variables, returning the number of variables created. -#[instrument(skip(infcx, body, promoted), level = "debug")] -pub(crate) fn renumber_mir<'tcx>( - infcx: &BorrowckInferCtxt<'tcx>, - body: &mut Body<'tcx>, - promoted: &mut IndexSlice>, -) { +#[instrument(skip(infcx, body), level = "debug")] +pub(crate) fn renumber_mir<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, body: &mut Body<'tcx>) { debug!(?body.arg_count); - - let mut renumberer = RegionRenumberer { infcx }; - - for body in promoted.iter_mut() { - renumberer.visit_body_preserves_cfg(body); - } - - renumberer.visit_body_preserves_cfg(body); + RegionRenumberer { infcx }.visit_body_preserves_cfg(body); } // The fields are used only for debugging output in `sccs_info`. diff --git a/compiler/rustc_borrowck/src/root_cx.rs b/compiler/rustc_borrowck/src/root_cx.rs index a082aba35b8a7..6e76cd59b5902 100644 --- a/compiler/rustc_borrowck/src/root_cx.rs +++ b/compiler/rustc_borrowck/src/root_cx.rs @@ -266,6 +266,14 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> { .iter() .chain(std::iter::once(self.root_def_id)); for def_id in all_bodies { + // The list of promoted from a given body is a flat list, + // in topological order from innermost to outermost. + let promoted = self.tcx.promoted_mir(def_id); + for &promoted_def_id in promoted { + let result = borrowck_collect_region_constraints(self, promoted_def_id); + self.collect_region_constraints_results.insert(promoted_def_id, result); + } + let result = borrowck_collect_region_constraints(self, def_id); self.collect_region_constraints_results.insert(def_id, result); } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 59874e82e920f..a1fc88fcb5b12 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1,7 +1,7 @@ //! This pass type-checks the MIR to ensure it is not broken. use std::rc::Rc; -use std::{fmt, iter, mem}; +use std::{fmt, iter}; use rustc_abi::FieldIdx; use rustc_data_structures::frozen::Frozen; @@ -87,7 +87,6 @@ mod relate_tys; /// /// - `infcx` -- inference context to use /// - `body` -- MIR body to type-check -/// - `promoted` -- map of promoted constants within `body` /// - `universal_regions` -- the universal regions from `body`s function signature /// - `location_table` -- for datalog polonius, the map between `Location`s and `RichLocation`s /// - `borrow_set` -- information about borrows occurring in `body` @@ -98,7 +97,6 @@ pub(crate) fn type_check<'tcx>( root_cx: &mut BorrowCheckRootCtxt<'tcx>, infcx: &BorrowckInferCtxt<'tcx>, body: &Body<'tcx>, - promoted: &IndexSlice>, universal_regions: UniversalRegions<'tcx>, location_table: &PoloniusLocationTable, borrow_set: &BorrowSet<'tcx>, @@ -150,7 +148,6 @@ pub(crate) fn type_check<'tcx>( infcx, last_span: body.span, body, - promoted, user_type_annotations: &body.user_type_annotations, region_bound_pairs: ®ion_bound_pairs, known_type_outlives_obligations: &known_type_outlives_obligations, @@ -214,9 +211,6 @@ struct TypeChecker<'a, 'tcx> { infcx: &'a BorrowckInferCtxt<'tcx>, last_span: Span, body: &'a Body<'tcx>, - /// The bodies of all promoteds. As promoteds have a completely separate CFG - /// recursing into them may corrupt your data structures if you're not careful. - promoted: &'a IndexSlice>, /// User type annotations are shared between the main MIR and the MIR of /// all of the promoted items. user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>, @@ -477,75 +471,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Ok(()) } - - fn check_promoted(&mut self, promoted_body: &'a Body<'tcx>, location: Location) { - // Determine the constraints from the promoted MIR by running the type - // checker on the promoted MIR, then transfer the constraints back to - // the main MIR, changing the locations to the provided location. - - let parent_body = mem::replace(&mut self.body, promoted_body); - - // Use new sets of constraints and closure bounds so that we can - // modify their locations. - let polonius_facts = &mut None; - let mut constraints = Default::default(); - let mut liveness_constraints = - LivenessValues::without_specific_points(Rc::new(DenseLocationMap::new(promoted_body))); - let mut deferred_closure_requirements = Default::default(); - - // Don't try to add borrow_region facts for the promoted MIR as they refer - // to the wrong locations. - let mut swap_constraints = |this: &mut Self| { - mem::swap(this.polonius_facts, polonius_facts); - mem::swap(&mut this.constraints.outlives_constraints, &mut constraints); - mem::swap(&mut this.constraints.liveness_constraints, &mut liveness_constraints); - mem::swap(this.deferred_closure_requirements, &mut deferred_closure_requirements); - }; - - swap_constraints(self); - - self.visit_body(promoted_body); - - self.body = parent_body; - - // Merge the outlives constraints back in, at the given location. - swap_constraints(self); - let locations = location.to_locations(); - for constraint in constraints.outlives().iter() { - let mut constraint = *constraint; - constraint.locations = locations; - if let ConstraintCategory::Return(_) - | ConstraintCategory::UseAsConst - | ConstraintCategory::UseAsStatic = constraint.category - { - // "Returning" from a promoted is an assignment to a - // temporary from the user's point of view. - constraint.category = ConstraintCategory::Boring; - } - self.constraints.outlives_constraints.push(constraint) - } - - // If there are nested bodies in promoteds, we also need to update their - // location to something in the actual body, not the promoted. - // - // We don't update the constraint categories of the resulting constraints - // as returns in nested bodies are a proper return, even if that nested body - // is in a promoted. - for (closure_def_id, args, _locations) in deferred_closure_requirements { - self.deferred_closure_requirements.push((closure_def_id, args, locations)); - } - - // If the region is live at least one location in the promoted MIR, - // then add a liveness constraint to the main MIR for this region - // at the location provided as an argument to this method - // - // add_location doesn't care about ordering so not a problem for the live regions to be - // unordered. - #[allow(rustc::potential_query_instability)] - for region in liveness_constraints.live_regions_unordered() { - self.constraints.liveness_constraints.add_location(region, location); - } - } } impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { @@ -1672,18 +1597,16 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { }; if let Some(uv) = maybe_uneval { - if uv.promoted.is_none() { - let tcx = self.tcx(); - let def_id = uv.def; - if tcx.def_kind(def_id) == DefKind::InlineConst { - let def_id = def_id.expect_local(); - let predicates = self.prove_closure_bounds(tcx, def_id, uv.args, location); - self.normalize_and_prove_instantiated_predicates( - def_id.to_def_id(), - predicates, - location.to_locations(), - ); - } + let tcx = self.tcx(); + let def_id = uv.def; + if matches!(tcx.def_kind(def_id), DefKind::InlineConst | DefKind::Promoted) { + let def_id = def_id.expect_local(); + let predicates = self.prove_closure_bounds(tcx, def_id, uv.args, location); + self.normalize_and_prove_instantiated_predicates( + def_id.to_def_id(), + predicates, + location.to_locations(), + ); } } } @@ -1732,32 +1655,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { }; if let Some(uv) = maybe_uneval { - if let Some(promoted) = uv.promoted { - let promoted_body = &self.promoted[promoted]; - self.check_promoted(promoted_body, location); - let promoted_ty = promoted_body.return_ty(); - if let Err(terr) = - self.eq_types(ty, promoted_ty, locations, ConstraintCategory::Boring) - { - span_mirbug!( - self, - promoted, - "bad promoted type ({:?}: {:?}): {:?}", - ty, - promoted_ty, - terr - ); - }; - } else { - self.ascribe_user_type( - constant.const_.ty(), - ty::UserType::new(ty::UserTypeKind::TypeOf( - uv.def, - UserArgs { args: uv.args, user_self_ty: None }, - )), - locations.span(self.body), - ); - } + self.ascribe_user_type( + constant.const_.ty(), + ty::UserType::new(ty::UserTypeKind::TypeOf( + uv.def, + UserArgs { args: uv.args, user_self_ty: None }, + )), + locations.span(self.body), + ); } else if let Some(static_def_id) = constant.check_static_ptr(tcx) { let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity().skip_norm_wip(); @@ -2502,7 +2407,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // length as the `typeck_root_args`. &args[..typeck_root_args.len()] } - DefKind::InlineConst => args.as_inline_const().parent_args(), + DefKind::InlineConst | DefKind::Promoted => args.as_inline_const().parent_args(), other => bug!("unexpected item {:?}", other), }; let parent_args = tcx.mk_args(parent_args); diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index 804d2757cf998..5b87650cdc634 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -615,7 +615,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { BodyOwnerKind::Const { .. } | BodyOwnerKind::Static(..) => { match tcx.def_kind(self.mir_def) { - DefKind::InlineConst => { + DefKind::InlineConst | DefKind::Promoted => { // This is required for `AscribeUserType` canonical query, which will call // `type_of(inline_const_def_id)`. That `type_of` would inject erased lifetimes // into borrowck, which is ICE #78174. diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index a4f33ea05b2d3..7df9eec29d1fa 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -7,10 +7,11 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir::LangItem; +use rustc_hir::def::DefKind; use rustc_infer::infer::TyCtxtInferExt; +use rustc_middle::bug; use rustc_middle::mir::*; use rustc_middle::ty::{self, AdtDef, Ty}; -use rustc_middle::{bug, mir}; use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt}; use tracing::instrument; @@ -355,14 +356,16 @@ where Const::Val(..) => None, }; - if let Some(mir::UnevaluatedConst { def, args: _, promoted }) = uneval { + if let Some(UnevaluatedConst { def, args: _, promoted: _ }) = uneval { + let is_promoted = cx.tcx.def_kind(def) == DefKind::Promoted; + // Use qualifs of the type for the promoted. Promoteds in MIR body should be possible // only for `NeedsNonConstDrop` with precise drop checking. This is the only const // check performed after the promotion. Verify that with an assertion. - assert!(promoted.is_none() || Q::ALLOW_PROMOTED); + assert!(!is_promoted || Q::ALLOW_PROMOTED); // Don't peak inside trait associated constants. - if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() { + if !is_promoted && cx.tcx.trait_of_assoc(def).is_none() { let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def); if !Q::in_qualifs(&qualifs) { diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index aa5697dfc9ced..a21cb423f69a4 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -28,30 +28,17 @@ fn setup_for_eval<'tcx>( cid: GlobalId<'tcx>, layout: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, (InternKind, MPlaceTy<'tcx>)> { - let tcx = *ecx.tcx; - assert!( - cid.promoted.is_some() - || matches!( - ecx.tcx.def_kind(cid.instance.def_id()), - DefKind::Const { .. } - | DefKind::Static { .. } - | DefKind::ConstParam - | DefKind::AnonConst - | DefKind::InlineConst - | DefKind::AssocConst { .. } - ), - "Unexpected DefKind: {:?}", - ecx.tcx.def_kind(cid.instance.def_id()) - ); assert!(layout.is_sized()); - let intern_kind = if cid.promoted.is_some() { - InternKind::Promoted - } else { - match tcx.static_mutability(cid.instance.def_id()) { - Some(m) => InternKind::Static(m), - None => InternKind::Constant, - } + let intern_kind = match ecx.tcx.def_kind(cid.instance.def_id()) { + DefKind::Static { mutability, .. } => InternKind::Static(mutability), + DefKind::Promoted => InternKind::Promoted, + DefKind::Const { .. } + | DefKind::ConstParam + | DefKind::AnonConst + | DefKind::InlineConst + | DefKind::AssocConst { .. } => InternKind::Constant, + dk => bug!("Unexpected DefKind: {dk:?}"), }; let return_place = if let InternKind::Static(_) = intern_kind { @@ -438,15 +425,14 @@ fn const_validate_mplace<'tcx>( let mut ref_tracking = RefTracking::new(mplace.clone(), mplace.layout.ty); let mut inner = false; while let Some((mplace, path)) = ref_tracking.next() { - let mode = match ecx.tcx.static_mutability(cid.instance.def_id()) { - _ if cid.promoted.is_some() => CtfeValidationMode::Promoted, - Some(mutbl) => CtfeValidationMode::Static { mutbl }, // a `static` - None => { - // This is a normal `const` (not promoted). - // The outermost allocation is always only copied, so having `UnsafeCell` in there - // is okay despite them being in immutable memory. - CtfeValidationMode::Const { allow_immutable_unsafe_cell: !inner } - } + let mode = match ecx.tcx.def_kind(cid.instance.def_id()) { + DefKind::Promoted => CtfeValidationMode::Promoted, + // a `static` + DefKind::Static { mutability, .. } => CtfeValidationMode::Static { mutbl: mutability }, + // This is a normal `const` (not promoted). + // The outermost allocation is always only copied, so having `UnsafeCell` in there + // is okay despite them being in immutable memory. + _ => CtfeValidationMode::Const { allow_immutable_unsafe_cell: !inner }, }; ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode) .report_err() diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 466dcff359829..7f247ccd7cd5c 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -314,12 +314,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { promoted: Option, ) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> { trace!("load mir(instance={:?}, promoted={:?})", instance, promoted); - let body = if let Some(promoted) = promoted { - let def = instance.def_id(); - &self.tcx.promoted_mir(def)[promoted] - } else { - M::load_mir(self, instance) - }; + let body = M::load_mir(self, instance); // do not continue if typeck errors occurred (can only occur in local crate) if let Some(err) = body.tainted_by_errors { throw_inval!(AlreadyReported(ReportedErrorInfo::non_const_eval_error(err))); diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index f5935a4742eea..1589f8e23a21d 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -66,6 +66,30 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { }; } + // provide junk type parameter defs for const blocks. + if let DefKind::Promoted | DefKind::InlineConst = tcx.def_kind(def_id) { + let def_id = def_id.to_def_id(); + let parent_def_id = tcx.typeck_root_def_id(def_id); + let parent_generics = tcx.generics_of(parent_def_id); + let own_params = vec![ty::GenericParamDef { + index: parent_generics.count() as u32, + name: rustc_span::sym::const_ty_placeholder, + def_id, + pure_wrt_drop: false, + kind: ty::GenericParamDefKind::Type { has_default: false, synthetic: false }, + }]; + let param_def_id_to_index = + own_params.iter().map(|param| (param.def_id, param.index)).collect(); + return ty::Generics { + parent: Some(parent_def_id), + parent_count: parent_generics.count(), + own_params, + param_def_id_to_index, + has_self: parent_generics.has_self, + has_late_bound_regions: None, + }; + } + let hir_id = tcx.local_def_id_to_hir_id(def_id); let node = tcx.hir_node(hir_id); @@ -350,17 +374,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { })); } - // provide junk type parameter defs for const blocks. - if let Node::ConstBlock(_) = node { - own_params.push(ty::GenericParamDef { - index: next_index(), - name: rustc_span::sym::const_ty_placeholder, - def_id: def_id.to_def_id(), - pure_wrt_drop: false, - kind: ty::GenericParamDefKind::Type { has_default: false, synthetic: false }, - }); - } - if let Node::OpaqueTy(&hir::OpaqueTy { .. }) = node { assert!(own_params.is_empty()); diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 3ac603fc715f3..65b8711698684 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -1,6 +1,7 @@ use core::ops::ControlFlow; use rustc_errors::{Applicability, StashKey, Suggestions}; +use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::VisitorExt; use rustc_hir::{self as hir, AmbigArg, HirId}; @@ -22,6 +23,11 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ use rustc_hir::*; use rustc_middle::ty::Ty; + if let DefKind::Promoted | DefKind::InlineConst = tcx.def_kind(def_id) { + let substs = ty::GenericArgs::identity_for_item(tcx, def_id); + return ty::EarlyBinder::bind(substs.as_inline_const().ty()); + } + // If we are computing `type_of` the synthesized associated type for an RPITIT in the impl // side, use `collect_return_position_impl_trait_in_trait_tys` to infer the value of the // associated type in the impl. @@ -222,8 +228,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ Node::AnonConst(_) => anon_const_type_of(&icx, def_id), Node::ConstBlock(_) => { - let args = ty::GenericArgs::identity_for_item(tcx, def_id.to_def_id()); - args.as_inline_const().ty() + bug!("InlineConst should have been handled by type_of") } Node::GenericParam(param) => match ¶m.kind { diff --git a/compiler/rustc_incremental/src/persist/clean.rs b/compiler/rustc_incremental/src/persist/clean.rs index f57e69fa2486e..45a85785ceee7 100644 --- a/compiler/rustc_incremental/src/persist/clean.rs +++ b/compiler/rustc_incremental/src/persist/clean.rs @@ -64,7 +64,7 @@ const BASE_IMPL: &[&str] = /// DepNodes for exported mir bodies, which is relevant in "executable" /// code, i.e., functions+methods -const BASE_MIR: &[&str] = &[label_strs::optimized_mir, label_strs::promoted_mir]; +const BASE_MIR: &[&str] = &[label_strs::optimized_mir, label_strs::mir_for_ctfe]; /// Struct, Enum and Union DepNodes /// diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index e90e67a943300..1309a9f1305bb 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -1134,12 +1134,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) { }); rustc_hir_analysis::check_crate(tcx); - // Freeze definitions as we don't add new ones at this point. - // We need to wait until now since we synthesize a by-move body - // for all coroutine-closures. - // - // This improves performance by allowing lock-free access to them. - tcx.untracked().definitions.freeze(); sess.time("MIR_borrow_checking", || { tcx.par_hir_body_owners(|def_id| { @@ -1165,6 +1159,12 @@ fn run_required_analyses(tcx: TyCtxt<'_>) { || tcx.hir_body_const_context(def_id).is_some() { tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id); + + if tcx.trivial_const(def_id).is_none() { + for &promoted in tcx.promoted_mir(def_id) { + tcx.ensure_ok().mir_drops_elaborated_and_const_checked(promoted); + } + } } if tcx.is_coroutine(def_id.to_def_id()) && (!tcx.is_async_drop_in_place_coroutine(def_id.to_def_id())) diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index a00fb59963ac2..c1185f682fcbf 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -240,7 +240,6 @@ provide! { tcx, def_id, other, cdata, trivial_const => { table } closure_saved_names_of_captured_variables => { table } mir_coroutine_witnesses => { table } - promoted_mir => { table } def_span => { table } def_ident_span => { table } lookup_stability => { table } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 58c7f88c08872..3e37ff3e6740c 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1849,13 +1849,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses); } } - let mut is_trivial = false; if encode_const { if let Some((val, ty)) = tcx.trivial_const(def_id) { - is_trivial = true; record!(self.tables.trivial_const[def_id.to_def_id()] <- (val, ty)); } else { - is_trivial = false; record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- tcx.mir_for_ctfe(def_id)); } @@ -1875,10 +1872,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } } } - if !is_trivial { - record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id)); - } - if self.tcx.is_coroutine(def_id.to_def_id()) && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id) { diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index c7b2eaa15ebfb..ef3d6747e2975 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -434,7 +434,6 @@ define_tables! { trivial_const: Table)>>, closure_saved_names_of_captured_variables: Table>>, mir_coroutine_witnesses: Table>>, - promoted_mir: Table>>>, thir_abstract_const: Table>>>, impl_parent: Table, const_conditions: Table>>, diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index de6a105ee2b7b..f14fb915b20a9 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -18,13 +18,13 @@ macro_rules! arena_types { rustc_data_structures::steal::Steal< rustc_index::IndexVec< rustc_middle::mir::Promoted, - rustc_middle::mir::Body<'tcx> + rustc_span::def_id::LocalDefId, > >, [decode] promoted: rustc_index::IndexVec< rustc_middle::mir::Promoted, - rustc_middle::mir::Body<'tcx> + rustc_span::def_id::LocalDefId, >, [decode] typeck_results: rustc_middle::ty::TypeckResults<'tcx>, [decode] borrowck_result: rustc_data_structures::fx::FxIndexMap< diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index c2357e370182e..f4a9fdadcebfa 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -292,7 +292,7 @@ impl<'tcx> TyCtxt<'tcx> { DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::AnonConst => { BodyOwnerKind::Const { inline: false } } - DefKind::InlineConst => BodyOwnerKind::Const { inline: true }, + DefKind::InlineConst | DefKind::Promoted => BodyOwnerKind::Const { inline: true }, DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => BodyOwnerKind::Fn, DefKind::Closure | DefKind::SyntheticCoroutineBody => BodyOwnerKind::Closure, DefKind::Static { safety: _, mutability, nested: false } => { @@ -1130,6 +1130,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh { let upstream_crates = upstream_crates(tcx); let resolutions = tcx.resolutions(()); + tcx.ensure_done().mir_keys(()); // We hash the final, remapped names of all local source files so we // don't have to include the path prefix remapping commandline args. diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index c59e6b6fa2151..095fefd43418e 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -179,12 +179,7 @@ impl<'a, 'tcx> MirDumper<'a, 'tcx> { self.tcx().def_path_str(body.source.def_id()) )); // ignore-tidy-odd-backticks the literal below is fine - write!(w, "// MIR for `{def_path}")?; - match body.source.promoted { - None => write!(w, "`")?, - Some(promoted) => write!(w, "::{promoted:?}`")?, - } - writeln!(w, " {} {}", self.disambiguator, self.pass_name)?; + writeln!(w, "// MIR for `{def_path}` {} {}", self.disambiguator, self.pass_name)?; if let Some(ref layout) = body.coroutine_layout_raw() { writeln!(w, "/* coroutine_layout = {layout:#?} */")?; } @@ -201,10 +196,6 @@ impl<'a, 'tcx> MirDumper<'a, 'tcx> { fn dump_path(&self, extension: &str, body: &Body<'tcx>) -> PathBuf { let tcx = self.tcx(); let source = body.source; - let promotion_id = match source.promoted { - Some(id) => format!("-{id:?}"), - None => String::new(), - }; let pass_num = if tcx.sess.opts.unstable_opts.dump_mir_exclude_pass_number { String::new() @@ -277,7 +268,7 @@ impl<'a, 'tcx> MirDumper<'a, 'tcx> { let pass_name = self.pass_name; let disambiguator = self.disambiguator; let file_name = format!( - "{crate_name}.{item_name}{shim_disambiguator}{promotion_id}{pass_num}.{pass_name}.{disambiguator}.{extension}", + "{crate_name}.{item_name}{shim_disambiguator}{pass_num}.{pass_name}.{disambiguator}.{extension}", ); file_path.push(&file_name); @@ -337,9 +328,12 @@ pub fn write_mir_pretty<'tcx>( let render_body = |w: &mut dyn io::Write, body| -> io::Result<()> { writer.write_mir_fn(body, w)?; - for body in tcx.promoted_mir(def_id) { - writeln!(w)?; - writer.write_mir_fn(body, w)?; + if let Some(def_id) = def_id.as_local() { + for body in tcx.promoted_mir(def_id) { + writeln!(w)?; + let body = tcx.mir_for_ctfe(body.to_def_id()); + writer.write_mir_fn(body, w)?; + } } Ok(()) }; @@ -621,20 +615,21 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io: } _ => tcx.is_closure_like(def_id), }; - match (kind, body.source.promoted) { - (_, Some(_)) => write!(w, "const ")?, // promoteds are the closest to consts - (DefKind::Const { .. } | DefKind::AssocConst { .. }, _) => write!(w, "const ")?, - (DefKind::Static { safety: _, mutability: hir::Mutability::Not, nested: false }, _) => { + match kind { + DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::Promoted => { + write!(w, "const ")? + } + DefKind::Static { safety: _, mutability: hir::Mutability::Not, nested: false } => { write!(w, "static ")? } - (DefKind::Static { safety: _, mutability: hir::Mutability::Mut, nested: false }, _) => { + DefKind::Static { safety: _, mutability: hir::Mutability::Mut, nested: false } => { write!(w, "static mut ")? } - (_, _) if is_function => write!(w, "fn ")?, + _ if is_function => write!(w, "fn ")?, // things like anon const, not an item - (DefKind::AnonConst | DefKind::InlineConst, _) => {} + DefKind::AnonConst | DefKind::InlineConst => {} // `global_asm!` have fake bodies, which we may dump after mir-build - (DefKind::GlobalAsm, _) => {} + DefKind::GlobalAsm => {} _ => bug!("Unexpected def kind {:?}", kind), } @@ -646,7 +641,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io: write!(w, "::{p:?}")?; } - if body.source.promoted.is_none() && is_function { + if is_function { write!(w, "(")?; // fn argument types. diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 16a8743a6d67b..c5977aad74a9c 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -162,6 +162,12 @@ macro_rules! make_mir_visitor { self.super_ascribe_user_ty(place, variance, user_ty, location); } + fn visit_user_type_annotation_index( + &mut self, + _index: $(& $mutability)? UserTypeAnnotationIndex, + ) { + } + fn visit_coverage( &mut self, kind: & $($mutability)? coverage::CoverageKind, @@ -786,10 +792,13 @@ macro_rules! make_mir_visitor { _adt_def, _variant_index, args, - _user_args, + user_args, _active_field_index ) => { self.visit_args(args, location); + if let Some(user_args) = user_args { + self.visit_user_type_annotation_index($(& $mutability)? *user_args); + } } AggregateKind::Closure(_, closure_args) => { self.visit_args(closure_args, location); @@ -959,11 +968,14 @@ macro_rules! make_mir_visitor { ) { let ConstOperand { span, - user_ty: _, // no visit method for this + user_ty, const_, } = constant; self.visit_span($(& $mutability)? *span); + if let Some(user_ty) = user_ty { + self.visit_user_type_annotation_index($(& $mutability)? *user_ty); + } match const_ { Const::Ty(_, ct) => self.visit_ty_const($(&$mutability)? *ct, location), Const::Val(_, ty) | Const::Unevaluated(_, ty) => { @@ -988,7 +1000,9 @@ macro_rules! make_mir_visitor { self.visit_source_scope($(& $mutability)? *scope); } - fn super_user_type_projection(&mut self, _ty: & $($mutability)? UserTypeProjection) {} + fn super_user_type_projection(&mut self, ty: & $($mutability)? UserTypeProjection) { + self.visit_user_type_annotation_index($(&$mutability)? ty.base); + } fn super_user_type_annotation( &mut self, diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index f0c367beefd65..99cdd53a7ec07 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -660,22 +660,28 @@ rustc_queries! { desc { "elaborating drops for `{}`", tcx.def_path_str(key) } } - query mir_for_ctfe( - key: DefId - ) -> &'tcx mir::Body<'tcx> { + query mir_for_ctfe(key: DefId) -> &'tcx mir::Body<'tcx> { desc { "caching mir of `{}` for CTFE", tcx.def_path_str(key) } cache_on_disk separate_provide_extern } + /// The `DefId` is the `DefId` of the containing MIR body. + /// This query creates new `DefId`s for promoted-out constants. query mir_promoted(key: LocalDefId) -> ( &'tcx Steal>, - &'tcx Steal>> + &'tcx IndexVec, ) { no_hash + feedable desc { "promoting constants in MIR for `{}`", tcx.def_path_str(key) } } + query promoted_mir(key: LocalDefId) -> &'tcx IndexVec { + cache_on_disk + desc { "promoted constants in MIR for `{}`", tcx.def_path_str(key) } + } + query closure_typeinfo(key: LocalDefId) -> ty::ClosureTypeInfo<'tcx> { desc { "finding symbols for captures of closure `{}`", @@ -758,17 +764,6 @@ rustc_queries! { arena_cache } - /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own - /// `DefId`. This function returns all promoteds in the specified body. The body references - /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because - /// after inlining a body may refer to promoteds from other bodies. In that case you still - /// need to use the `DefId` of the original body. - query promoted_mir(key: DefId) -> &'tcx IndexVec> { - desc { "optimizing promoted MIR for `{}`", tcx.def_path_str(key) } - cache_on_disk - separate_provide_extern - } - /// Erases regions from `ty` to yield a new type. /// Normally you would just use `tcx.erase_and_anonymize_regions(value)`, /// however, which uses this query as a kind of cache. diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index 3bbbe3c184eb0..3785d05a630ed 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -706,10 +706,7 @@ impl<'a, 'tcx> Decodable> } } -impl<'a, 'tcx> Decodable> - for &'tcx IndexVec> -{ - #[inline] +impl<'a, 'tcx> Decodable> for &'tcx IndexVec { fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self { RefDecodable::decode(d) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index b5c1033700246..7a2f404173d9f 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -60,7 +60,7 @@ use crate::metadata::ModChild; use crate::middle::codegen_fn_attrs::{CodegenFnAttrs, TargetFeature}; use crate::middle::resolve_bound_vars; use crate::mir::interpret::{self, Allocation, ConstAllocation}; -use crate::mir::{Body, Local, Place, PlaceElem, ProjectionKind, Promoted}; +use crate::mir::{Body, Local, Place, PlaceElem, ProjectionKind}; use crate::query::{IntoQueryKey, LocalCrate, Providers, QuerySystem, TyCtxtAt}; use crate::thir::Thir; use crate::traits; @@ -858,13 +858,6 @@ impl<'tcx> TyCtxt<'tcx> { self.arena.alloc(Steal::new(mir)) } - pub fn alloc_steal_promoted( - self, - promoted: IndexVec>, - ) -> &'tcx Steal>> { - self.arena.alloc(Steal::new(promoted)) - } - pub fn mk_adt_def( self, did: DefId, @@ -1372,6 +1365,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn iter_local_def_id(self) -> impl Iterator { // Depend on the `analysis` query to ensure compilation if finished. self.ensure_ok().analysis(()); + self.ensure_done().mir_keys(()); let definitions = &self.untracked.definitions; gen { @@ -1393,6 +1387,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn def_path_table(self) -> &'tcx rustc_hir::definitions::DefPathTable { // Depend on the `analysis` query to ensure compilation if finished. self.ensure_ok().analysis(()); + self.ensure_done().mir_keys(()); // Freeze definitions once we start iterating on them, to prevent adding new ones // while iterating. If some query needs to add definitions, it should be `ensure`d above. @@ -1405,6 +1400,8 @@ impl<'tcx> TyCtxt<'tcx> { // Create a dependency to the crate to be sure we re-execute this when the amount of // definitions change. self.ensure_ok().hir_crate_items(()); + self.ensure_ok().analysis(()); + self.ensure_done().mir_keys(()); // Freeze definitions once we start iterating on them, to prevent adding new ones // while iterating. If some query needs to add definitions, it should be `ensure`d above. self.untracked.definitions.freeze().def_path_hash_to_def_index_map() diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index d425ba7a99658..ac194132e1502 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -512,6 +512,7 @@ impl<'tcx> Instance<'tcx> { | DefKind::Static { .. } | DefKind::Ctor(_, CtorKind::Fn) | DefKind::Closure + | DefKind::Promoted | DefKind::SyntheticCoroutineBody, "`Instance::try_resolve` should only be used to resolve instances of \ functions, statics, and consts; to resolve associated types, use \ diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 9b87b1b1dcf5c..dd29475223dfc 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1723,6 +1723,7 @@ impl<'tcx> TyCtxt<'tcx> { | DefKind::AssocConst { .. } | DefKind::Ctor(..) | DefKind::AnonConst + | DefKind::Promoted | DefKind::InlineConst => self.mir_for_ctfe(def), // If the caller wants `mir_for_ctfe` of a function they should not be using // `instance_mir`, so we'll assume const fn also wants the optimized version. diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index 8beb00c5deffa..f25c6fe6c741d 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -33,13 +33,18 @@ impl<'tcx> crate::MirLint<'tcx> for KnownPanicsLint { } let def_id = body.source.def_id().expect_local(); + + // Only run const prop on functions, methods, closures and associated constants. + // Skip anon_const/statics/consts because they'll be evaluated by miri anyway + let should_run = + |def_kind| matches!(def_kind, DefKind::AssocConst { .. }) || def_kind.is_fn_like(); + let def_kind = tcx.def_kind(def_id); - let is_fn_like = def_kind.is_fn_like(); - let is_assoc_const = matches!(def_kind, DefKind::AssocConst { .. }); + let should_run = should_run(def_kind) || + // Run on promoted too, as their code does not appear in the enclosing body any more. + (matches!(def_kind, DefKind::Promoted) && should_run(tcx.def_kind(tcx.local_parent(def_id)))); - // Only run const prop on functions, methods, closures and associated constants - if !is_fn_like && !is_assoc_const { - // skip anon_const/statics/consts because they'll be evaluated by miri anyway + if !should_run { trace!("KnownPanicsLint skipped for {:?}", def_id); return; } diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 21a55654cd844..bc1eae278c564 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -350,6 +350,16 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet { } } + // Now, the add promoted MIR from all those bodies into the set. + let mut promoted = Vec::new(); + for &item in set.iter() { + if tcx.trivial_const(item).is_none() { + let promoted_in_item = tcx.promoted_mir(item); + promoted.extend_from_slice(&promoted_in_item.raw); + } + } + set.extend(promoted.into_iter()); + set } @@ -428,9 +438,10 @@ fn mir_built(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal> { fn mir_promoted( tcx: TyCtxt<'_>, def: LocalDefId, -) -> (&Steal>, &Steal>>) { +) -> (&Steal>, &IndexVec) { debug_assert!(!tcx.is_trivial_const(def), "Tried to get mir_promoted of a trivial const"); debug_assert!(!tcx.is_constructor(def.to_def_id())); + debug_assert_ne!(tcx.def_kind(def), DefKind::Promoted); // Ensure that we compute the `mir_const_qualif` for constants at // this point, before we steal the mir-const result. @@ -483,7 +494,7 @@ fn mir_promoted( lint_tail_expr_drop_order::run_lint(tcx, def, &body); let promoted = promote_pass.promoted_fragments.into_inner(); - (tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted)) + (tcx.alloc_steal_mir(body), tcx.arena.alloc(promoted)) } /// Compute the MIR that is used during CTFE (and thus has no optimizations run on it) @@ -531,8 +542,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> & None }; - let is_fn_like = tcx.def_kind(def).is_fn_like(); - if is_fn_like { + if tcx.def_kind(def).is_fn_like() { // Do not compute the mir call graph without said call graph actually being used. if pm::should_run_pass(tcx, &inline::Inline, pm::Optimizations::Allowed) || inline::ForceInline::should_run_pass_for_callee(tcx, def.to_def_id()) @@ -834,19 +844,6 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> { /// Fetch all the promoteds of an item and prepare their MIR bodies to be ready for /// constant evaluation once all generic parameters become known. -fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec> { - if tcx.is_constructor(def.to_def_id()) { - return tcx.arena.alloc(IndexVec::new()); - } - - if !tcx.is_synthetic_mir(def) { - tcx.ensure_done().mir_borrowck(tcx.typeck_root_def_id_local(def)); - } - let mut promoted = tcx.mir_promoted(def).1.steal(); - - for body in &mut promoted { - run_analysis_to_runtime_passes(tcx, body); - } - - tcx.arena.alloc(promoted) +fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec { + tcx.mir_promoted(def).1 } diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index a47b3ce64ed23..c7c6331a4011e 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -15,14 +15,18 @@ use std::{assert_matches, cmp, iter, mem}; use either::{Left, Right}; use rustc_const_eval::check_consts::{ConstCx, qualifs}; -use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_hir as hir; use rustc_hir::def::DefKind; +use rustc_hir::definitions::{DefPathData, PerParentDisambiguatorState}; use rustc_index::{IndexSlice, IndexVec}; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::{self, GenericArgs, List, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{ + self, GenericArgs, List, Ty, TyCtxt, TypeVisitableExt, UserTypeAnnotationIndex, +}; use rustc_middle::{bug, mir, span_bug}; +use rustc_span::def_id::LocalDefId; use rustc_span::{Span, Spanned}; use tracing::{debug, instrument}; @@ -34,12 +38,12 @@ use tracing::{debug, instrument}; /// After this pass is run, `promoted_fragments` will hold the MIR body corresponding to each /// newly created `Constant`. #[derive(Default)] -pub(super) struct PromoteTemps<'tcx> { +pub(super) struct PromoteTemps { // Must use `Cell` because `run_pass` takes `&self`, not `&mut self`. - pub promoted_fragments: Cell>>, + pub promoted_fragments: Cell>, } -impl<'tcx> crate::MirPass<'tcx> for PromoteTemps<'tcx> { +impl<'tcx> crate::MirPass<'tcx> for PromoteTemps { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // There's not really any point in promoting errorful MIR. // @@ -48,9 +52,6 @@ impl<'tcx> crate::MirPass<'tcx> for PromoteTemps<'tcx> { debug!("PromoteTemps: MIR had errors"); return; } - if body.source.promoted.is_some() { - return; - } let ccx = ConstCx::new(tcx, body); let (mut temps, all_candidates) = collect_temps_and_candidates(&ccx); @@ -715,6 +716,7 @@ struct Promoter<'a, 'tcx> { promoted: Body<'tcx>, temps: &'a mut IndexVec, extra_statements: &'a mut Vec<(Location, Statement<'tcx>)>, + disambiguator: &'a mut PerParentDisambiguatorState, /// Used to assemble the required_consts list while building the promoted. required_consts: Vec>, @@ -863,79 +865,53 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { new_temp } - fn promote_candidate( - mut self, - candidate: Candidate, - next_promoted_index: Promoted, - ) -> Body<'tcx> { - let def = self.source.source.def_id(); - let (mut rvalue, promoted_op) = { - let promoted = &mut self.promoted; - let tcx = self.tcx; - let mut promoted_operand = |ty, span| { - promoted.span = span; - promoted.local_decls[RETURN_PLACE] = LocalDecl::new(ty, span); - let args = - tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(tcx, def)); - let uneval = - mir::UnevaluatedConst { def, args, promoted: Some(next_promoted_index) }; - - ConstOperand { span, user_ty: None, const_: Const::Unevaluated(uneval, ty) } - }; + fn promote_candidate(mut self, candidate: Candidate) -> LocalDefId { + let tcx = self.tcx; - let blocks = self.source.basic_blocks.as_mut(); - let local_decls = &mut self.source.local_decls; - let loc = candidate.location; - let statement = &mut blocks[loc.block].statements[loc.statement_index]; - let StatementKind::Assign(box (_, Rvalue::Ref(region, borrow_kind, place))) = - &mut statement.kind - else { - bug!() - }; + let blocks = self.source.basic_blocks.as_mut_preserves_cfg(); + let local_decls = &mut self.source.local_decls; + let loc = candidate.location; - // Use the underlying local for this (necessarily interior) borrow. - debug_assert!(region.is_erased()); - let ty = local_decls[place.local].ty; - let span = statement.source_info.span; + let statement = &mut blocks[loc.block].statements[loc.statement_index]; + let source_info = statement.source_info; + let span = source_info.span; + self.promoted.span = span; - let ref_ty = - Ty::new_ref(tcx, tcx.lifetimes.re_erased, ty, borrow_kind.to_mutbl_lossy()); + let StatementKind::Assign(box (_, Rvalue::Ref(region, borrow_kind, place))) = + &mut statement.kind + else { + bug!() + }; + debug_assert!(region.is_erased()); + // Use the underlying local for this (necessarily interior) borrow. + let ty = local_decls[place.local].ty; + let ref_ty = Ty::new_ref(tcx, tcx.lifetimes.re_erased, ty, borrow_kind.to_mutbl_lossy()); + self.promoted.local_decls[RETURN_PLACE] = LocalDecl::new(ref_ty, span); + + place.projection = { let mut projection = vec![PlaceElem::Deref]; projection.extend(place.projection); - place.projection = tcx.mk_place_elems(&projection); - - // Create a temp to hold the promoted reference. - // This is because `*r` requires `r` to be a local, - // otherwise we would use the `promoted` directly. - let mut promoted_ref = LocalDecl::new(ref_ty, span); - promoted_ref.source_info = statement.source_info; - let promoted_ref = local_decls.push(promoted_ref); - assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref); - - let promoted_operand = promoted_operand(ref_ty, span); - let promoted_ref_statement = Statement::new( - statement.source_info, - StatementKind::Assign(Box::new(( - Place::from(promoted_ref), - Rvalue::Use(Operand::Constant(Box::new(promoted_operand))), - ))), - ); - self.extra_statements.push((loc, promoted_ref_statement)); - - ( - Rvalue::Ref( - tcx.lifetimes.re_erased, - *borrow_kind, - Place { - local: mem::replace(&mut place.local, promoted_ref), - projection: List::empty(), - }, - ), - promoted_operand, - ) + tcx.mk_place_elems(&projection) }; + // Create a temp to hold the promoted reference. + // This is because `*r` requires `r` to be a local, + // otherwise we would use the `promoted` directly. + let mut promoted_ref = LocalDecl::new(ref_ty, span); + promoted_ref.source_info = source_info; + let promoted_ref = local_decls.push(promoted_ref); + assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref); + + let mut rvalue = Rvalue::Ref( + tcx.lifetimes.re_erased, + *borrow_kind, + Place { + local: mem::replace(&mut place.local, promoted_ref), + projection: List::empty(), + }, + ); + assert_eq!(self.new_block(), START_BLOCK); self.visit_rvalue( &mut rvalue, @@ -945,15 +921,65 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let span = self.promoted.span; self.assign(RETURN_PLACE, rvalue, span); - // Now that we did promotion, we know whether we'll want to add this to `required_consts` of + // Copy user type annotations from the original body to the promoted. + // We don't want to keep all the original annotations, as they may create + // constants that borrowck will not be able to verify. However, we still + // need some of them to borrow-check the promoted itself. + // + // We don't remove the cloned annotations from the original body, as they + // are harmless there. + let mut annotation_renumber = + RenumberUserTypeAnnotations { tcx, mapping: FxIndexSet::default() }; + annotation_renumber.visit_body_preserves_cfg(&mut self.promoted); + self.promoted.user_type_annotations = annotation_renumber + .mapping + .iter() + .map(|&original_index| self.source.user_type_annotations[original_index].clone()) + .collect(); + + let source_def_id = self.source.source.def_id().expect_local(); + let feeder = tcx.at(span).create_def( + source_def_id, + None, + DefKind::Promoted, + Some(DefPathData::Promoted), + self.disambiguator, + ); + feeder.feed_hir(); + + let def_id = feeder.def_id(); + self.promoted.source = MirSource::item(def_id.to_def_id()); + self.promoted.set_required_consts(self.required_consts); + + let parent_args = tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item( + tcx, + tcx.typeck_root_def_id(source_def_id.to_def_id()), + )); + let args = + ty::InlineConstArgs::new(tcx, ty::InlineConstArgsParts { parent_args, ty: ref_ty }) + .args; + let uneval = UnevaluatedConst { def: self.promoted.source.def_id(), args, promoted: None }; + + feeder.mir_promoted((tcx.alloc_steal_mir(self.promoted), tcx.arena.alloc(IndexVec::new()))); + + let promoted_op = + ConstOperand { span, user_ty: None, const_: Const::Unevaluated(uneval, ref_ty) }; + // Now that we did promotion, we know whether we'll want to add this to // the surrounding MIR body. if self.add_to_required { - self.source.required_consts.as_mut().unwrap().push(promoted_op); + self.source.required_consts.as_mut().unwrap().push(promoted_op.clone()); } + let promoted_operand = Operand::Constant(Box::new(promoted_op)); + let promoted_ref_statement = Statement::new( + source_info, + StatementKind::Assign(Box::new(( + Place::from(promoted_ref), + Rvalue::Use(promoted_operand), + ))), + ); + self.extra_statements.push((loc, promoted_ref_statement)); - self.promoted.set_required_consts(self.required_consts); - - self.promoted + def_id } } @@ -978,12 +1004,29 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> { } } +/// Replaces type annotation indices. +struct RenumberUserTypeAnnotations<'tcx> { + tcx: TyCtxt<'tcx>, + mapping: FxIndexSet, +} + +impl<'tcx> MutVisitor<'tcx> for RenumberUserTypeAnnotations<'tcx> { + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx + } + + fn visit_user_type_annotation_index(&mut self, annotation: &mut UserTypeAnnotationIndex) { + let (new_index, _) = self.mapping.insert_full(*annotation); + *annotation = UserTypeAnnotationIndex::from_usize(new_index); + } +} + fn promote_candidates<'tcx>( body: &mut Body<'tcx>, tcx: TyCtxt<'tcx>, mut temps: IndexVec, candidates: Vec, -) -> IndexVec> { +) -> IndexVec { // Visit candidates in reverse, in case they're nested. debug!(promote_candidates = ?candidates); @@ -992,6 +1035,7 @@ fn promote_candidates<'tcx>( return IndexVec::new(); } + let mut disambiguator = PerParentDisambiguatorState::new(body.source.def_id().expect_local()); let mut promotions = IndexVec::new(); let mut extra_statements = vec![]; @@ -1032,13 +1076,13 @@ fn promote_candidates<'tcx>( source: body, temps: &mut temps, extra_statements: &mut extra_statements, + disambiguator: &mut disambiguator, keep_original: false, add_to_required: false, required_consts: Vec::new(), }; - let mut promoted = promoter.promote_candidate(candidate, promotions.next_index()); - promoted.source.promoted = Some(promotions.next_index()); + let promoted = promoter.promote_candidate(candidate); promotions.push(promoted); } diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index cb08ca0757876..5154739fd66de 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -149,6 +149,10 @@ fn adt_sizedness_constraint<'tcx>( /// See `ParamEnv` struct definition for details. fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { + if let DefKind::Promoted = tcx.def_kind(def_id) { + return tcx.param_env(tcx.parent(def_id)); + } + // Compute the bounds on Self and the type parameters. let ty::InstantiatedPredicates { predicates, .. } = tcx.predicates_of(def_id).instantiate_identity(tcx); From 58a35e292e7fc5aea7fc63b7f92554c246b64002 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Wed, 29 Apr 2026 02:00:11 +0000 Subject: [PATCH 09/15] Bless incremental tests. --- tests/incremental/hashes/for_loops.rs | 4 ++-- tests/incremental/hashes/inherent_impls.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/incremental/hashes/for_loops.rs b/tests/incremental/hashes/for_loops.rs index 17d67a32ff55c..df76e77e4fc7c 100644 --- a/tests/incremental/hashes/for_loops.rs +++ b/tests/incremental/hashes/for_loops.rs @@ -104,9 +104,9 @@ pub fn change_iterable() { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg="bpass2", except="opt_hir_owner_nodes, promoted_mir")] +#[rustc_clean(cfg="bpass2", except="opt_hir_owner_nodes")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(cfg="bpass5", except="opt_hir_owner_nodes, promoted_mir")] +#[rustc_clean(cfg="bpass5", except="opt_hir_owner_nodes")] #[rustc_clean(cfg="bpass6")] pub fn change_iterable() { let mut _x = 0; diff --git a/tests/incremental/hashes/inherent_impls.rs b/tests/incremental/hashes/inherent_impls.rs index da3fb1b2ee5fe..1d258836b0f84 100644 --- a/tests/incremental/hashes/inherent_impls.rs +++ b/tests/incremental/hashes/inherent_impls.rs @@ -57,9 +57,9 @@ impl Foo { #[rustc_clean(except="opt_hir_owner_nodes", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] impl Foo { - #[rustc_clean(cfg="bpass2",except="opt_hir_owner_nodes,optimized_mir,promoted_mir,typeck_root")] + #[rustc_clean(cfg="bpass2",except="opt_hir_owner_nodes,optimized_mir,typeck_root")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(cfg="bpass5",except="opt_hir_owner_nodes,optimized_mir,promoted_mir,typeck_root")] + #[rustc_clean(cfg="bpass5",except="opt_hir_owner_nodes,optimized_mir,typeck_root")] #[rustc_clean(cfg="bpass6")] pub fn method_body() { println!("Hello, world!"); From 78cf760b4ab8b9caf3b3d280bbf821dcd6ac7c3f Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Tue, 28 Apr 2026 02:13:37 +0000 Subject: [PATCH 10/15] Bless ui. --- .../defaults-cyclic-fail.stderr | 2 +- tests/ui/borrowck/issue-81899.stderr | 2 +- .../issue-88434-minimal-example.stderr | 2 +- ...-88434-removal-index-should-be-less.stderr | 2 +- .../borrowck/move-error-in-promoted-2.stderr | 9 - .../ui/borrowck/move-error-in-promoted.stderr | 5 - tests/ui/const-generics/issues/issue-90318.rs | 2 + .../const-generics/issues/issue-90318.stderr | 75 +- tests/ui/consts/const-eval/issue-50814.rs | 2 +- tests/ui/consts/const-eval/issue-50814.stderr | 38 +- .../consts/const-eval/raw-bytes.32bit.stderr | 12 +- .../consts/const-eval/raw-bytes.64bit.stderr | 12 +- tests/ui/consts/const-eval/ub-ref-ptr.stderr | 4 +- tests/ui/consts/const-eval/ub-wide-ptr.stderr | 12 +- tests/ui/consts/const-slice-array-deref.rs | 1 + .../ui/consts/const-slice-array-deref.stderr | 10 +- .../interior-mut-const-via-union.32bit.stderr | 4 +- .../interior-mut-const-via-union.64bit.stderr | 10 +- .../ui/consts/interior-mut-const-via-union.rs | 5 +- tests/ui/consts/promoted_size_overflow.stderr | 2 +- .../ui/consts/recursive-const-in-impl.stderr | 2 +- .../interpret-in-promoted.noopt.stderr | 2 +- .../interpret-in-promoted.opt.stderr | 2 +- tests/ui/lint/issue-117949.noopt.stderr | 24 +- tests/ui/lint/issue-117949.opt.stderr | 24 +- ...sue-117949.opt_with_overflow_checks.stderr | 24 +- .../ui/lint/lint-overflowing-ops.noopt.stderr | 740 +++++++++--------- tests/ui/lint/lint-overflowing-ops.opt.stderr | 740 +++++++++--------- ...lowing-ops.opt_with_overflow_checks.stderr | 740 +++++++++--------- ...ram-closure-approximate-lower-bound.stderr | 8 + .../promoted-annotation.stderr | 2 +- 31 files changed, 1279 insertions(+), 1240 deletions(-) diff --git a/tests/ui/associated-consts/defaults-cyclic-fail.stderr b/tests/ui/associated-consts/defaults-cyclic-fail.stderr index 31974d955611f..f9ed838940f4a 100644 --- a/tests/ui/associated-consts/defaults-cyclic-fail.stderr +++ b/tests/ui/associated-consts/defaults-cyclic-fail.stderr @@ -20,7 +20,7 @@ note: ...which requires const-evaluating + checking `Tr::B`... LL | const B: u8 = Self::A; | ^^^^^^^ = note: ...which again requires simplifying constant for the type system `Tr::A`, completing the cycle -note: cycle used when optimizing promoted MIR for `main` +note: cycle used when elaborating drops for `main::{promoted#1}` --> $DIR/defaults-cyclic-fail.rs:16:16 | LL | assert_eq!(<() as Tr>::A, 0); diff --git a/tests/ui/borrowck/issue-81899.stderr b/tests/ui/borrowck/issue-81899.stderr index 96fe2ad709a5d..ee8172d33cb3e 100644 --- a/tests/ui/borrowck/issue-81899.stderr +++ b/tests/ui/borrowck/issue-81899.stderr @@ -2,7 +2,7 @@ error[E0080]: evaluation panicked: explicit panic --> $DIR/issue-81899.rs:6:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); - | ^^^^^^^^^^^^^^ evaluation of `_CONST` failed inside this call + | ^^^^^^^^^^^^^^ evaluation of `_CONST::{promoted#0}` failed inside this call | note: inside `f::<{closure@$DIR/issue-81899.rs:6:31: 6:34}>` --> $DIR/issue-81899.rs:13:5 diff --git a/tests/ui/borrowck/issue-88434-minimal-example.stderr b/tests/ui/borrowck/issue-88434-minimal-example.stderr index 3921c47640e62..bac17b931b1bf 100644 --- a/tests/ui/borrowck/issue-88434-minimal-example.stderr +++ b/tests/ui/borrowck/issue-88434-minimal-example.stderr @@ -2,7 +2,7 @@ error[E0080]: evaluation panicked: explicit panic --> $DIR/issue-88434-minimal-example.rs:5:22 | LL | const _CONST: &() = &f(&|_| {}); - | ^^^^^^^^^^ evaluation of `_CONST` failed inside this call + | ^^^^^^^^^^ evaluation of `_CONST::{promoted#0}` failed inside this call | note: inside `f::<{closure@$DIR/issue-88434-minimal-example.rs:5:25: 5:28}>` --> $DIR/issue-88434-minimal-example.rs:12:5 diff --git a/tests/ui/borrowck/issue-88434-removal-index-should-be-less.stderr b/tests/ui/borrowck/issue-88434-removal-index-should-be-less.stderr index c7f945dc6ef56..5c82c0a248ae7 100644 --- a/tests/ui/borrowck/issue-88434-removal-index-should-be-less.stderr +++ b/tests/ui/borrowck/issue-88434-removal-index-should-be-less.stderr @@ -2,7 +2,7 @@ error[E0080]: evaluation panicked: explicit panic --> $DIR/issue-88434-removal-index-should-be-less.rs:5:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); - | ^^^^^^^^^^^^^^ evaluation of `_CONST` failed inside this call + | ^^^^^^^^^^^^^^ evaluation of `_CONST::{promoted#0}` failed inside this call | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:5:31: 5:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:12:5 diff --git a/tests/ui/borrowck/move-error-in-promoted-2.stderr b/tests/ui/borrowck/move-error-in-promoted-2.stderr index 1e9b1d5209cb6..0d5edadcb4641 100644 --- a/tests/ui/borrowck/move-error-in-promoted-2.stderr +++ b/tests/ui/borrowck/move-error-in-promoted-2.stderr @@ -6,15 +6,6 @@ LL | &([S][0],); | | | cannot move out of here | move occurs because value has type `S`, which does not implement the `Copy` trait - | -note: if `S` implemented `Clone`, you could clone the value - --> $DIR/move-error-in-promoted-2.rs:3:1 - | -LL | struct S; - | ^^^^^^^^ consider implementing `Clone` for this type -... -LL | &([S][0],); - | ------ you could clone this value error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/move-error-in-promoted.stderr b/tests/ui/borrowck/move-error-in-promoted.stderr index 8d42df24e2772..03c0297c5a980 100644 --- a/tests/ui/borrowck/move-error-in-promoted.stderr +++ b/tests/ui/borrowck/move-error-in-promoted.stderr @@ -6,11 +6,6 @@ LL | let _ = S1(C[0]).clone(); | | | cannot move out of here | move occurs because value has type `S2`, which does not implement the `Copy` trait - | -help: consider cloning the value if the performance cost is acceptable - | -LL | let _ = S1(C[0].clone()).clone(); - | ++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-90318.rs b/tests/ui/const-generics/issues/issue-90318.rs index 35b0dd216a1af..b11b768889133 100644 --- a/tests/ui/const-generics/issues/issue-90318.rs +++ b/tests/ui/const-generics/issues/issue-90318.rs @@ -13,6 +13,7 @@ fn consume(_val: T) where If<{ TypeId::of::() != TypeId::of::<()>() }>: True, //~^ ERROR overly complex generic constant + //~| ERROR cycle detected when borrow-checking `consume::{constant#0}` { } @@ -20,6 +21,7 @@ fn test() where If<{ TypeId::of::() != TypeId::of::<()>() }>: True, //~^ ERROR overly complex generic constant + //~| ERROR cycle detected when borrow-checking `test::{constant#0}` { } diff --git a/tests/ui/const-generics/issues/issue-90318.stderr b/tests/ui/const-generics/issues/issue-90318.stderr index f13fd795d7a10..05029844a9654 100644 --- a/tests/ui/const-generics/issues/issue-90318.stderr +++ b/tests/ui/const-generics/issues/issue-90318.stderr @@ -10,7 +10,7 @@ LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, = note: this operation may be supported in the future error: overly complex generic constant - --> $DIR/issue-90318.rs:21:8 + --> $DIR/issue-90318.rs:22:8 | LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, | ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,5 +20,76 @@ LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future -error: aborting due to 2 previous errors +error[E0391]: cycle detected when borrow-checking `consume::{constant#0}` + --> $DIR/issue-90318.rs:14:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: ...which requires normalizing `Binder { value: TraitPredicate(() != TypeId::of::<()>() }> as True>, polarity:Positive), bound_vars: [] }`... + --> $DIR/issue-90318.rs:14:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires evaluating type-level constant... + --> $DIR/issue-90318.rs:14:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires const-evaluating + checking `consume::{constant#0}`... + --> $DIR/issue-90318.rs:14:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires caching mir of `consume::{constant#0}` for CTFE... + --> $DIR/issue-90318.rs:14:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires elaborating drops for `consume::{constant#0}`... + --> $DIR/issue-90318.rs:14:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: ...which again requires borrow-checking `consume::{constant#0}`, completing the cycle + = note: cycle used when running analysis passes on crate `issue_90318` + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +error[E0391]: cycle detected when borrow-checking `test::{constant#0}` + --> $DIR/issue-90318.rs:22:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: ...which requires normalizing `Binder { value: TraitPredicate(() != TypeId::of::<()>() }> as True>, polarity:Positive), bound_vars: [] }`... + --> $DIR/issue-90318.rs:22:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires evaluating type-level constant... + --> $DIR/issue-90318.rs:22:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires const-evaluating + checking `test::{constant#0}`... + --> $DIR/issue-90318.rs:22:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires caching mir of `test::{constant#0}` for CTFE... + --> $DIR/issue-90318.rs:22:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires elaborating drops for `test::{constant#0}`... + --> $DIR/issue-90318.rs:22:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: ...which again requires borrow-checking `test::{constant#0}`, completing the cycle + = note: cycle used when running analysis passes on crate `issue_90318` + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/consts/const-eval/issue-50814.rs b/tests/ui/consts/const-eval/issue-50814.rs index 3901a2c0c9316..d0b159a5050ec 100644 --- a/tests/ui/consts/const-eval/issue-50814.rs +++ b/tests/ui/consts/const-eval/issue-50814.rs @@ -15,7 +15,7 @@ struct Sum(A, B); impl Unsigned for Sum { const MAX: u8 = A::MAX + B::MAX; //~^ ERROR attempt to compute `u8::MAX + u8::MAX`, which would overflow - //~| ERROR attempt to compute `u8::MAX + u8::MAX`, which would overflow + //~| NOTE evaluation of ` as Unsigned>::MAX` failed here } fn foo(_: T) -> &'static u8 { diff --git a/tests/ui/consts/const-eval/issue-50814.stderr b/tests/ui/consts/const-eval/issue-50814.stderr index 1287c83ae0ff8..c9d74568fea63 100644 --- a/tests/ui/consts/const-eval/issue-50814.stderr +++ b/tests/ui/consts/const-eval/issue-50814.stderr @@ -10,42 +10,6 @@ note: erroneous constant encountered LL | &Sum::::MAX | ^^^^^^^^^^^^^^^^^^ -error[E0080]: attempt to compute `u8::MAX + u8::MAX`, which would overflow - --> $DIR/issue-50814.rs:16:21 - | -LL | const MAX: u8 = A::MAX + B::MAX; - | ^^^^^^^^^^^^^^^ evaluation of ` as Unsigned>::MAX` failed here - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -note: erroneous constant encountered - --> $DIR/issue-50814.rs:22:6 - | -LL | &Sum::::MAX - | ^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -note: erroneous constant encountered - --> $DIR/issue-50814.rs:22:5 - | -LL | &Sum::::MAX - | ^^^^^^^^^^^^^^^^^^^ - -note: erroneous constant encountered - --> $DIR/issue-50814.rs:22:6 - | -LL | &Sum::::MAX - | ^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -note: the above error was encountered while instantiating `fn foo::` - --> $DIR/issue-50814.rs:27:5 - | -LL | foo(0); - | ^^^^^^ - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr index 6ae23c6b24b1d..cb531054a7f5e 100644 --- a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr @@ -331,10 +331,10 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us } error[E0080]: constructing invalid value of type &[bool; 1]: at .[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:160:1 + --> $DIR/raw-bytes.rs:160:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { @@ -348,10 +348,10 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..0, encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:164:1 + --> $DIR/raw-bytes.rs:164:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { @@ -365,10 +365,10 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..1[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:167:1 + --> $DIR/raw-bytes.rs:167:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { diff --git a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr index 0f1e095719f54..81051944aab0c 100644 --- a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr @@ -331,10 +331,10 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us } error[E0080]: constructing invalid value of type &[bool; 1]: at .[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:160:1 + --> $DIR/raw-bytes.rs:160:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { @@ -348,10 +348,10 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..0, encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:164:1 + --> $DIR/raw-bytes.rs:164:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { @@ -365,10 +365,10 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..1[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:167:1 + --> $DIR/raw-bytes.rs:167:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { diff --git a/tests/ui/consts/const-eval/ub-ref-ptr.stderr b/tests/ui/consts/const-eval/ub-ref-ptr.stderr index 17ddea05e93f7..61fe1020421d6 100644 --- a/tests/ui/consts/const-eval/ub-ref-ptr.stderr +++ b/tests/ui/consts/const-eval/ub-ref-ptr.stderr @@ -66,7 +66,7 @@ error[E0080]: unable to turn pointer into integer --> $DIR/ub-ref-ptr.rs:42:39 | LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `REF_AS_USIZE_SLICE` failed here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `REF_AS_USIZE_SLICE::{promoted#0}` failed here | = help: this code performed an operation that depends on the underlying bytes representing a pointer = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported @@ -81,7 +81,7 @@ error[E0080]: unable to turn pointer into integer --> $DIR/ub-ref-ptr.rs:45:86 | LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) }; - | ^^^^^^^^^^^^^^^^^^^^ evaluation of `REF_AS_USIZE_BOX_SLICE` failed here + | ^^^^^^^^^^^^^^^^^^^^ evaluation of `REF_AS_USIZE_BOX_SLICE::{promoted#0}` failed here | = help: this code performed an operation that depends on the underlying bytes representing a pointer = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported diff --git a/tests/ui/consts/const-eval/ub-wide-ptr.stderr b/tests/ui/consts/const-eval/ub-wide-ptr.stderr index 9603710e4fd8c..b3ad67e228562 100644 --- a/tests/ui/consts/const-eval/ub-wide-ptr.stderr +++ b/tests/ui/consts/const-eval/ub-wide-ptr.stderr @@ -133,10 +133,10 @@ LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3) = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: constructing invalid value of type &[bool; 1]: at .[0], encountered 0x03, but expected a boolean - --> $DIR/ub-wide-ptr.rs:86:1 + --> $DIR/ub-wide-ptr.rs:86:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { @@ -150,10 +150,10 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..0, encountered 0x03, but expected a boolean - --> $DIR/ub-wide-ptr.rs:92:1 + --> $DIR/ub-wide-ptr.rs:92:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { @@ -167,10 +167,10 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..1[0], encountered 0x03, but expected a boolean - --> $DIR/ub-wide-ptr.rs:95:1 + --> $DIR/ub-wide-ptr.rs:95:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { diff --git a/tests/ui/consts/const-slice-array-deref.rs b/tests/ui/consts/const-slice-array-deref.rs index 99563ac968c91..e56e968e9ec0e 100644 --- a/tests/ui/consts/const-slice-array-deref.rs +++ b/tests/ui/consts/const-slice-array-deref.rs @@ -4,5 +4,6 @@ const ONE: [u16] = [1]; const TWO: &'static u16 = &ONE[0]; //~^ ERROR cannot move a value of type `[u16]` +//~| ERROR cannot move a value of type `[u16]` fn main() {} diff --git a/tests/ui/consts/const-slice-array-deref.stderr b/tests/ui/consts/const-slice-array-deref.stderr index e7513d01cd0e9..eae08b782dbe3 100644 --- a/tests/ui/consts/const-slice-array-deref.stderr +++ b/tests/ui/consts/const-slice-array-deref.stderr @@ -21,7 +21,15 @@ error[E0161]: cannot move a value of type `[u16]` LL | const TWO: &'static u16 = &ONE[0]; | ^^^ the size of `[u16]` cannot be statically determined -error: aborting due to 3 previous errors +error[E0161]: cannot move a value of type `[u16]` + --> $DIR/const-slice-array-deref.rs:5:28 + | +LL | const TWO: &'static u16 = &ONE[0]; + | ^^^ the size of `[u16]` cannot be statically determined + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 4 previous errors Some errors have detailed explanations: E0161, E0277, E0308. For more information about an error, try `rustc --explain E0161`. diff --git a/tests/ui/consts/interior-mut-const-via-union.32bit.stderr b/tests/ui/consts/interior-mut-const-via-union.32bit.stderr index 64a178b6913dc..39650d449a73f 100644 --- a/tests/ui/consts/interior-mut-const-via-union.32bit.stderr +++ b/tests/ui/consts/interior-mut-const-via-union.32bit.stderr @@ -1,8 +1,8 @@ error[E0080]: constructing invalid value of type &S: at ..y..0, encountered `UnsafeCell` in read-only memory --> $DIR/interior-mut-const-via-union.rs:34:1 | -LL | fn main() { - | ^^^^^^^^^ it is undefined behavior to use this value +LL | let _: &'static _ = &C; + | ^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { diff --git a/tests/ui/consts/interior-mut-const-via-union.64bit.stderr b/tests/ui/consts/interior-mut-const-via-union.64bit.stderr index f2301560faae7..cca359724c869 100644 --- a/tests/ui/consts/interior-mut-const-via-union.64bit.stderr +++ b/tests/ui/consts/interior-mut-const-via-union.64bit.stderr @@ -1,8 +1,8 @@ error[E0080]: constructing invalid value of type &S: at ..y..0, encountered `UnsafeCell` in read-only memory - --> $DIR/interior-mut-const-via-union.rs:34:1 + --> $DIR/interior-mut-const-via-union.rs:35:25 | -LL | fn main() { - | ^^^^^^^^^ it is undefined behavior to use this value +LL | let _: &'static _ = &C; + | ^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { @@ -10,13 +10,13 @@ LL | fn main() { } note: erroneous constant encountered - --> $DIR/interior-mut-const-via-union.rs:36:25 + --> $DIR/interior-mut-const-via-union.rs:35:25 | LL | let _: &'static _ = &C; | ^^ note: erroneous constant encountered - --> $DIR/interior-mut-const-via-union.rs:36:25 + --> $DIR/interior-mut-const-via-union.rs:35:25 | LL | let _: &'static _ = &C; | ^^ diff --git a/tests/ui/consts/interior-mut-const-via-union.rs b/tests/ui/consts/interior-mut-const-via-union.rs index cba3b36bd98a0..3cd6fcf8dd5b6 100644 --- a/tests/ui/consts/interior-mut-const-via-union.rs +++ b/tests/ui/consts/interior-mut-const-via-union.rs @@ -31,7 +31,6 @@ const C: S = { s }; -fn main() { //~ ERROR encountered `UnsafeCell` in read-only memory - // FIXME the span here is wrong, should be pointing at the line below, not above. - let _: &'static _ = &C; +fn main() { + let _: &'static _ = &C; //~ ERROR encountered `UnsafeCell` in read-only memory } diff --git a/tests/ui/consts/promoted_size_overflow.stderr b/tests/ui/consts/promoted_size_overflow.stderr index 529b232c77c65..98f9d70b34607 100644 --- a/tests/ui/consts/promoted_size_overflow.stderr +++ b/tests/ui/consts/promoted_size_overflow.stderr @@ -2,7 +2,7 @@ error[E0080]: values of the type `[u8; 4611686018427387903]` are too big for the --> $DIR/promoted_size_overflow.rs:3:29 | LL | const _: &'static [Data] = &[]; - | ^^ evaluation of `_` failed here + | ^^ evaluation of `_::{promoted#0}` failed here error: aborting due to 1 previous error diff --git a/tests/ui/consts/recursive-const-in-impl.stderr b/tests/ui/consts/recursive-const-in-impl.stderr index c53ce701566ed..bd144fd5f4a46 100644 --- a/tests/ui/consts/recursive-const-in-impl.stderr +++ b/tests/ui/consts/recursive-const-in-impl.stderr @@ -5,7 +5,7 @@ LL | println!("{}", Thing::::X); | ^^^^^^^^^^^^^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "14"]` attribute to your crate (`recursive_const_in_impl`) - = note: query depth increased by 9 when simplifying constant for the type system `main::promoted[0]` + = note: query depth increased by 9 when simplifying constant for the type system `main::{promoted#0}` error: aborting due to 1 previous error diff --git a/tests/ui/consts/required-consts/interpret-in-promoted.noopt.stderr b/tests/ui/consts/required-consts/interpret-in-promoted.noopt.stderr index 12c5acd02a490..ca5e80c6232a8 100644 --- a/tests/ui/consts/required-consts/interpret-in-promoted.noopt.stderr +++ b/tests/ui/consts/required-consts/interpret-in-promoted.noopt.stderr @@ -2,7 +2,7 @@ error[E0080]: entering unreachable code --> $DIR/interpret-in-promoted.rs:15:28 | LL | let _x: &'static () = &ub(); - | ^^^^ evaluation of `FOO` failed inside this call + | ^^^^ evaluation of `FOO::{promoted#0}` failed inside this call | note: inside `ub` --> $DIR/interpret-in-promoted.rs:9:5 diff --git a/tests/ui/consts/required-consts/interpret-in-promoted.opt.stderr b/tests/ui/consts/required-consts/interpret-in-promoted.opt.stderr index 12c5acd02a490..ca5e80c6232a8 100644 --- a/tests/ui/consts/required-consts/interpret-in-promoted.opt.stderr +++ b/tests/ui/consts/required-consts/interpret-in-promoted.opt.stderr @@ -2,7 +2,7 @@ error[E0080]: entering unreachable code --> $DIR/interpret-in-promoted.rs:15:28 | LL | let _x: &'static () = &ub(); - | ^^^^ evaluation of `FOO` failed inside this call + | ^^^^ evaluation of `FOO::{promoted#0}` failed inside this call | note: inside `ub` --> $DIR/interpret-in-promoted.rs:9:5 diff --git a/tests/ui/lint/issue-117949.noopt.stderr b/tests/ui/lint/issue-117949.noopt.stderr index 607488e2a4af8..d27d418e1b407 100644 --- a/tests/ui/lint/issue-117949.noopt.stderr +++ b/tests/ui/lint/issue-117949.noopt.stderr @@ -1,16 +1,16 @@ error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:16:24 + --> $DIR/issue-117949.rs:12:24 | -LL | format_args!("{}", 5 * i32::MAX); - | ^^^^^^^^^^^^ attempt to compute `5_i32 * i32::MAX`, which would overflow +LL | format_args!("{}", 1 << 32); + | ^^^^^^^ attempt to shift left by `32_i32`, which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:15:24 + --> $DIR/issue-117949.rs:13:24 | -LL | format_args!("{}", -5 - i32::MAX); - | ^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow +LL | format_args!("{}", 1 >> 32); + | ^^^^^^^ attempt to shift right by `32_i32`, which would overflow error: this arithmetic operation will overflow --> $DIR/issue-117949.rs:14:24 @@ -19,16 +19,16 @@ LL | format_args!("{}", 1 + i32::MAX); | ^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:13:24 + --> $DIR/issue-117949.rs:15:24 | -LL | format_args!("{}", 1 >> 32); - | ^^^^^^^ attempt to shift right by `32_i32`, which would overflow +LL | format_args!("{}", -5 - i32::MAX); + | ^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:12:24 + --> $DIR/issue-117949.rs:16:24 | -LL | format_args!("{}", 1 << 32); - | ^^^^^^^ attempt to shift left by `32_i32`, which would overflow +LL | format_args!("{}", 5 * i32::MAX); + | ^^^^^^^^^^^^ attempt to compute `5_i32 * i32::MAX`, which would overflow error: this operation will panic at runtime --> $DIR/issue-117949.rs:17:24 diff --git a/tests/ui/lint/issue-117949.opt.stderr b/tests/ui/lint/issue-117949.opt.stderr index 607488e2a4af8..d27d418e1b407 100644 --- a/tests/ui/lint/issue-117949.opt.stderr +++ b/tests/ui/lint/issue-117949.opt.stderr @@ -1,16 +1,16 @@ error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:16:24 + --> $DIR/issue-117949.rs:12:24 | -LL | format_args!("{}", 5 * i32::MAX); - | ^^^^^^^^^^^^ attempt to compute `5_i32 * i32::MAX`, which would overflow +LL | format_args!("{}", 1 << 32); + | ^^^^^^^ attempt to shift left by `32_i32`, which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:15:24 + --> $DIR/issue-117949.rs:13:24 | -LL | format_args!("{}", -5 - i32::MAX); - | ^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow +LL | format_args!("{}", 1 >> 32); + | ^^^^^^^ attempt to shift right by `32_i32`, which would overflow error: this arithmetic operation will overflow --> $DIR/issue-117949.rs:14:24 @@ -19,16 +19,16 @@ LL | format_args!("{}", 1 + i32::MAX); | ^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:13:24 + --> $DIR/issue-117949.rs:15:24 | -LL | format_args!("{}", 1 >> 32); - | ^^^^^^^ attempt to shift right by `32_i32`, which would overflow +LL | format_args!("{}", -5 - i32::MAX); + | ^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:12:24 + --> $DIR/issue-117949.rs:16:24 | -LL | format_args!("{}", 1 << 32); - | ^^^^^^^ attempt to shift left by `32_i32`, which would overflow +LL | format_args!("{}", 5 * i32::MAX); + | ^^^^^^^^^^^^ attempt to compute `5_i32 * i32::MAX`, which would overflow error: this operation will panic at runtime --> $DIR/issue-117949.rs:17:24 diff --git a/tests/ui/lint/issue-117949.opt_with_overflow_checks.stderr b/tests/ui/lint/issue-117949.opt_with_overflow_checks.stderr index 607488e2a4af8..d27d418e1b407 100644 --- a/tests/ui/lint/issue-117949.opt_with_overflow_checks.stderr +++ b/tests/ui/lint/issue-117949.opt_with_overflow_checks.stderr @@ -1,16 +1,16 @@ error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:16:24 + --> $DIR/issue-117949.rs:12:24 | -LL | format_args!("{}", 5 * i32::MAX); - | ^^^^^^^^^^^^ attempt to compute `5_i32 * i32::MAX`, which would overflow +LL | format_args!("{}", 1 << 32); + | ^^^^^^^ attempt to shift left by `32_i32`, which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:15:24 + --> $DIR/issue-117949.rs:13:24 | -LL | format_args!("{}", -5 - i32::MAX); - | ^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow +LL | format_args!("{}", 1 >> 32); + | ^^^^^^^ attempt to shift right by `32_i32`, which would overflow error: this arithmetic operation will overflow --> $DIR/issue-117949.rs:14:24 @@ -19,16 +19,16 @@ LL | format_args!("{}", 1 + i32::MAX); | ^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:13:24 + --> $DIR/issue-117949.rs:15:24 | -LL | format_args!("{}", 1 >> 32); - | ^^^^^^^ attempt to shift right by `32_i32`, which would overflow +LL | format_args!("{}", -5 - i32::MAX); + | ^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow error: this arithmetic operation will overflow - --> $DIR/issue-117949.rs:12:24 + --> $DIR/issue-117949.rs:16:24 | -LL | format_args!("{}", 1 << 32); - | ^^^^^^^ attempt to shift left by `32_i32`, which would overflow +LL | format_args!("{}", 5 * i32::MAX); + | ^^^^^^^^^^^^ attempt to compute `5_i32 * i32::MAX`, which would overflow error: this operation will panic at runtime --> $DIR/issue-117949.rs:17:24 diff --git a/tests/ui/lint/lint-overflowing-ops.noopt.stderr b/tests/ui/lint/lint-overflowing-ops.noopt.stderr index 1b7b73cec38d5..c85031fa8983b 100644 --- a/tests/ui/lint/lint-overflowing-ops.noopt.stderr +++ b/tests/ui/lint/lint-overflowing-ops.noopt.stderr @@ -11,346 +11,64 @@ LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:226:15 - | -LL | let _n = &(isize::MAX * 5); - | ^^^^^^^^^^^^^^^^ attempt to compute `isize::MAX * 5_isize`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:223:15 - | -LL | let _n = &(i128::MAX * 5); - | ^^^^^^^^^^^^^^^ attempt to compute `i128::MAX * 5_i128`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:220:15 - | -LL | let _n = &(i64::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `i64::MAX * 5_i64`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:217:15 - | -LL | let _n = &(i32::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `i32::MAX * 5_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:214:15 - | -LL | let _n = &(i16::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `i16::MAX * 5_i16`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:211:15 - | -LL | let _n = &(i8::MAX * i8::MAX); - | ^^^^^^^^^^^^^^^^^^^ attempt to compute `i8::MAX * i8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:208:15 - | -LL | let _n = &(usize::MAX * 5); - | ^^^^^^^^^^^^^^^^ attempt to compute `usize::MAX * 5_usize`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:205:15 - | -LL | let _n = &(u128::MAX * 5); - | ^^^^^^^^^^^^^^^ attempt to compute `u128::MAX * 5_u128`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:202:15 - | -LL | let _n = &(u64::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `u64::MAX * 5_u64`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:199:15 - | -LL | let _n = &(u32::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `u32::MAX * 5_u32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:196:15 - | -LL | let _n = &(u16::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `u16::MAX * 5_u16`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:193:15 - | -LL | let _n = &(u8::MAX * 5); - | ^^^^^^^^^^^^^ attempt to compute `u8::MAX * 5_u8`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:188:15 - | -LL | let _n = &(-i8::MIN); - | ^^^^^^^^^^ attempt to negate `i8::MIN`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:185:15 - | -LL | let _n = &(1usize - 5); - | ^^^^^^^^^^^^ attempt to compute `1_usize - 5_usize`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:182:15 - | -LL | let _n = &(-5isize - isize::MAX); - | ^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_isize - isize::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:179:15 - | -LL | let _n = &(-5i128 - i128::MAX); - | ^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i128 - i128::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:176:15 - | -LL | let _n = &(-5i64 - i64::MAX); - | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i64 - i64::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:173:15 - | -LL | let _n = &(-5i32 - i32::MAX); - | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:170:15 - | -LL | let _n = &(-5i16 - i16::MAX); - | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i16 - i16::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:167:15 - | -LL | let _n = &(-5i8 - i8::MAX); - | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i8 - i8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:164:15 - | -LL | let _n = &(1u128 - 5); - | ^^^^^^^^^^^ attempt to compute `1_u128 - 5_u128`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:161:15 - | -LL | let _n = &(1u64 - 5); - | ^^^^^^^^^^ attempt to compute `1_u64 - 5_u64`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:158:15 - | -LL | let _n = &(1u32 - 5); - | ^^^^^^^^^^ attempt to compute `1_u32 - 5_u32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:155:15 - | -LL | let _n = &(1u16 - 5); - | ^^^^^^^^^^ attempt to compute `1_u16 - 5_u16`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:152:15 - | -LL | let _n = &(1u8 - 5); - | ^^^^^^^^^ attempt to compute `1_u8 - 5_u8`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:147:15 - | -LL | let _n = &(1usize + usize::MAX); - | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_usize + usize::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:144:15 - | -LL | let _n = &(1isize + isize::MAX); - | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_isize + isize::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:141:15 - | -LL | let _n = &(1i128 + i128::MAX); - | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_i128 + i128::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:138:15 - | -LL | let _n = &(1i64 + i64::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i64 + i64::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:135:15 - | -LL | let _n = &(1i32 + i32::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:132:15 - | -LL | let _n = &(1i16 + i16::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i16 + i16::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:129:15 - | -LL | let _n = &(1i8 + i8::MAX); - | ^^^^^^^^^^^^^^^ attempt to compute `1_i8 + i8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:126:15 - | -LL | let _n = &(1u128 + u128::MAX); - | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_u128 + u128::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:123:15 - | -LL | let _n = &(1u64 + u64::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u64 + u64::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:120:15 - | -LL | let _n = &(1u32 + u32::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u32 + u32::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:117:15 - | -LL | let _n = &(1u16 + u16::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u16 + u16::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:114:15 - | -LL | let _n = &(1u8 + u8::MAX); - | ^^^^^^^^^^^^^^^ attempt to compute `1_u8 + u8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:110:15 - | -LL | let _n = &(1i64 >> [64][0]); - | ^^^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:107:15 - | -LL | let _n = &(1_usize >> BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:104:15 - | -LL | let _n = &(1_isize >> BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:101:15 - | -LL | let _n = &(1i128 >> 128); - | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:98:15 - | -LL | let _n = &(1i64 >> 64); - | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:95:15 - | -LL | let _n = &(1i32 >> 32); - | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:92:15 - | -LL | let _n = &(1i16 >> 16); - | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:89:15 - | -LL | let _n = &(1i8 >> 8); - | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:86:15 + --> $DIR/lint-overflowing-ops.rs:29:15 | -LL | let _n = &(1u128 >> 128); - | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow +LL | let _n = &(1u8 << 8); + | ^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:83:15 + --> $DIR/lint-overflowing-ops.rs:31:14 | -LL | let _n = &(1u64 >> 64); - | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +LL | let _n = 1u16 << 16; + | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:80:15 + --> $DIR/lint-overflowing-ops.rs:32:15 | -LL | let _n = &(1u32 >> 32); - | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +LL | let _n = &(1u16 << 16); + | ^^^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:77:15 + --> $DIR/lint-overflowing-ops.rs:34:14 | -LL | let _n = &(1u16 >> 16); - | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +LL | let _n = 1u32 << 32; + | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:74:15 + --> $DIR/lint-overflowing-ops.rs:35:15 | -LL | let _n = &(1u8 >> 8); - | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +LL | let _n = &(1u32 << 32); + | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:65:15 + --> $DIR/lint-overflowing-ops.rs:37:14 | -LL | let _n = &(1 << -1); - | ^^^^^^^^^ attempt to shift left by `-1_i32`, which would overflow +LL | let _n = 1u64 << 64; + | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:62:15 + --> $DIR/lint-overflowing-ops.rs:38:15 | -LL | let _n = &(1_usize << BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +LL | let _n = &(1u64 << 64); + | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:59:15 + --> $DIR/lint-overflowing-ops.rs:40:14 | -LL | let _n = &(1_isize << BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +LL | let _n = 1u128 << 128; + | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:56:15 + --> $DIR/lint-overflowing-ops.rs:41:15 | -LL | let _n = &(1i128 << 128); +LL | let _n = &(1u128 << 128); | ^^^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:53:15 - | -LL | let _n = &(1i64 << 64); - | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:50:15 - | -LL | let _n = &(1i32 << 32); - | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:47:15 + --> $DIR/lint-overflowing-ops.rs:43:14 | -LL | let _n = &(1i16 << 16); - | ^^^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow +LL | let _n = 1i8 << 8; + | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:44:15 @@ -359,100 +77,76 @@ LL | let _n = &(1i8 << 8); | ^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:41:15 - | -LL | let _n = &(1u128 << 128); - | ^^^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:38:15 - | -LL | let _n = &(1u64 << 64); - | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:35:15 + --> $DIR/lint-overflowing-ops.rs:46:14 | -LL | let _n = &(1u32 << 32); - | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow +LL | let _n = 1i16 << 16; + | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:32:15 + --> $DIR/lint-overflowing-ops.rs:47:15 | -LL | let _n = &(1u16 << 16); +LL | let _n = &(1i16 << 16); | ^^^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:29:15 - | -LL | let _n = &(1u8 << 8); - | ^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:31:14 - | -LL | let _n = 1u16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:34:14 + --> $DIR/lint-overflowing-ops.rs:49:14 | -LL | let _n = 1u32 << 32; +LL | let _n = 1i32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:37:14 + --> $DIR/lint-overflowing-ops.rs:50:15 | -LL | let _n = 1u64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow +LL | let _n = &(1i32 << 32); + | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:40:14 + --> $DIR/lint-overflowing-ops.rs:52:14 | -LL | let _n = 1u128 << 128; - | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow +LL | let _n = 1i64 << 64; + | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:43:14 + --> $DIR/lint-overflowing-ops.rs:53:15 | -LL | let _n = 1i8 << 8; - | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow +LL | let _n = &(1i64 << 64); + | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:46:14 + --> $DIR/lint-overflowing-ops.rs:55:14 | -LL | let _n = 1i16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow +LL | let _n = 1i128 << 128; + | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:49:14 + --> $DIR/lint-overflowing-ops.rs:56:15 | -LL | let _n = 1i32 << 32; - | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow +LL | let _n = &(1i128 << 128); + | ^^^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:52:14 + --> $DIR/lint-overflowing-ops.rs:58:14 | -LL | let _n = 1i64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow +LL | let _n = 1_isize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:55:14 + --> $DIR/lint-overflowing-ops.rs:59:15 | -LL | let _n = 1i128 << 128; - | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow +LL | let _n = &(1_isize << BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:58:14 + --> $DIR/lint-overflowing-ops.rs:61:14 | -LL | let _n = 1_isize << BITS; +LL | let _n = 1_usize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:61:14 + --> $DIR/lint-overflowing-ops.rs:62:15 | -LL | let _n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +LL | let _n = &(1_usize << BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:64:14 @@ -460,6 +154,12 @@ error: this arithmetic operation will overflow LL | let _n = 1 << -1; | ^^^^^^^ attempt to shift left by `-1_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:65:15 + | +LL | let _n = &(1 << -1); + | ^^^^^^^^^ attempt to shift left by `-1_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:69:14 | @@ -484,47 +184,95 @@ error: this arithmetic operation will overflow LL | let _n = 1u8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:74:15 + | +LL | let _n = &(1u8 >> 8); + | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:76:14 | LL | let _n = 1u16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:77:15 + | +LL | let _n = &(1u16 >> 16); + | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:79:14 | LL | let _n = 1u32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:80:15 + | +LL | let _n = &(1u32 >> 32); + | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:82:14 | LL | let _n = 1u64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:83:15 + | +LL | let _n = &(1u64 >> 64); + | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:85:14 | LL | let _n = 1u128 >> 128; | ^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:86:15 + | +LL | let _n = &(1u128 >> 128); + | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:88:14 | LL | let _n = 1i8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:89:15 + | +LL | let _n = &(1i8 >> 8); + | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:91:14 | LL | let _n = 1i16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:92:15 + | +LL | let _n = &(1i16 >> 16); + | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:94:14 | -LL | let _n = 1i32 >> 32; - | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +LL | let _n = 1i32 >> 32; + | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:95:15 + | +LL | let _n = &(1i32 >> 32); + | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:97:14 @@ -532,252 +280,504 @@ error: this arithmetic operation will overflow LL | let _n = 1i64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:98:15 + | +LL | let _n = &(1i64 >> 64); + | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:100:14 | LL | let _n = 1i128 >> 128; | ^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:101:15 + | +LL | let _n = &(1i128 >> 128); + | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:103:14 | LL | let _n = 1_isize >> BITS; | ^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:104:15 + | +LL | let _n = &(1_isize >> BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:106:14 | LL | let _n = 1_usize >> BITS; | ^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:107:15 + | +LL | let _n = &(1_usize >> BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:109:14 | LL | let _n = 1i64 >> [64][0]; | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:110:15 + | +LL | let _n = &(1i64 >> [64][0]); + | ^^^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:113:14 | LL | let _n = 1u8 + u8::MAX; | ^^^^^^^^^^^^^ attempt to compute `1_u8 + u8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:114:15 + | +LL | let _n = &(1u8 + u8::MAX); + | ^^^^^^^^^^^^^^^ attempt to compute `1_u8 + u8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:116:14 | LL | let _n = 1u16 + u16::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_u16 + u16::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:117:15 + | +LL | let _n = &(1u16 + u16::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u16 + u16::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:119:14 | LL | let _n = 1u32 + u32::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_u32 + u32::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:120:15 + | +LL | let _n = &(1u32 + u32::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u32 + u32::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:122:14 | LL | let _n = 1u64 + u64::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_u64 + u64::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:123:15 + | +LL | let _n = &(1u64 + u64::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u64 + u64::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:125:14 | LL | let _n = 1u128 + u128::MAX; | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u128 + u128::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:126:15 + | +LL | let _n = &(1u128 + u128::MAX); + | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_u128 + u128::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:128:14 | LL | let _n = 1i8 + i8::MAX; | ^^^^^^^^^^^^^ attempt to compute `1_i8 + i8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:129:15 + | +LL | let _n = &(1i8 + i8::MAX); + | ^^^^^^^^^^^^^^^ attempt to compute `1_i8 + i8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:131:14 | LL | let _n = 1i16 + i16::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_i16 + i16::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:132:15 + | +LL | let _n = &(1i16 + i16::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i16 + i16::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:134:14 | LL | let _n = 1i32 + i32::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:135:15 + | +LL | let _n = &(1i32 + i32::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:137:14 | LL | let _n = 1i64 + i64::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_i64 + i64::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:138:15 + | +LL | let _n = &(1i64 + i64::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i64 + i64::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:140:14 | LL | let _n = 1i128 + i128::MAX; | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i128 + i128::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:141:15 + | +LL | let _n = &(1i128 + i128::MAX); + | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_i128 + i128::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:143:14 | LL | let _n = 1isize + isize::MAX; | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_isize + isize::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:144:15 + | +LL | let _n = &(1isize + isize::MAX); + | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_isize + isize::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:146:14 | LL | let _n = 1usize + usize::MAX; | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_usize + usize::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:147:15 + | +LL | let _n = &(1usize + usize::MAX); + | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_usize + usize::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:151:14 | LL | let _n = 1u8 - 5; | ^^^^^^^ attempt to compute `1_u8 - 5_u8`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:152:15 + | +LL | let _n = &(1u8 - 5); + | ^^^^^^^^^ attempt to compute `1_u8 - 5_u8`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:154:14 | LL | let _n = 1u16 - 5; | ^^^^^^^^ attempt to compute `1_u16 - 5_u16`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:155:15 + | +LL | let _n = &(1u16 - 5); + | ^^^^^^^^^^ attempt to compute `1_u16 - 5_u16`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:157:14 | LL | let _n = 1u32 - 5; | ^^^^^^^^ attempt to compute `1_u32 - 5_u32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:158:15 + | +LL | let _n = &(1u32 - 5); + | ^^^^^^^^^^ attempt to compute `1_u32 - 5_u32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:160:14 | LL | let _n = 1u64 - 5 ; | ^^^^^^^^ attempt to compute `1_u64 - 5_u64`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:161:15 + | +LL | let _n = &(1u64 - 5); + | ^^^^^^^^^^ attempt to compute `1_u64 - 5_u64`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:163:14 | LL | let _n = 1u128 - 5 ; | ^^^^^^^^^ attempt to compute `1_u128 - 5_u128`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:164:15 + | +LL | let _n = &(1u128 - 5); + | ^^^^^^^^^^^ attempt to compute `1_u128 - 5_u128`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:166:14 | LL | let _n = -5i8 - i8::MAX; | ^^^^^^^^^^^^^^ attempt to compute `-5_i8 - i8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:167:15 + | +LL | let _n = &(-5i8 - i8::MAX); + | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i8 - i8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:169:14 | LL | let _n = -5i16 - i16::MAX; | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i16 - i16::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:170:15 + | +LL | let _n = &(-5i16 - i16::MAX); + | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i16 - i16::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:172:14 | LL | let _n = -5i32 - i32::MAX; | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:173:15 + | +LL | let _n = &(-5i32 - i32::MAX); + | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:175:14 | LL | let _n = -5i64 - i64::MAX; | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i64 - i64::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:176:15 + | +LL | let _n = &(-5i64 - i64::MAX); + | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i64 - i64::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:178:14 | LL | let _n = -5i128 - i128::MAX; | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i128 - i128::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:179:15 + | +LL | let _n = &(-5i128 - i128::MAX); + | ^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i128 - i128::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:181:14 | LL | let _n = -5isize - isize::MAX; | ^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_isize - isize::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:182:15 + | +LL | let _n = &(-5isize - isize::MAX); + | ^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_isize - isize::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:184:14 | LL | let _n = 1usize - 5; | ^^^^^^^^^^ attempt to compute `1_usize - 5_usize`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:185:15 + | +LL | let _n = &(1usize - 5); + | ^^^^^^^^^^^^ attempt to compute `1_usize - 5_usize`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:187:14 | LL | let _n = -i8::MIN; | ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:188:15 + | +LL | let _n = &(-i8::MIN); + | ^^^^^^^^^^ attempt to negate `i8::MIN`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:192:14 | LL | let _n = u8::MAX * 5; | ^^^^^^^^^^^ attempt to compute `u8::MAX * 5_u8`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:193:15 + | +LL | let _n = &(u8::MAX * 5); + | ^^^^^^^^^^^^^ attempt to compute `u8::MAX * 5_u8`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:195:14 | LL | let _n = u16::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `u16::MAX * 5_u16`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:196:15 + | +LL | let _n = &(u16::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `u16::MAX * 5_u16`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:198:14 | LL | let _n = u32::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `u32::MAX * 5_u32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:199:15 + | +LL | let _n = &(u32::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `u32::MAX * 5_u32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:201:14 | LL | let _n = u64::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `u64::MAX * 5_u64`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:202:15 + | +LL | let _n = &(u64::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `u64::MAX * 5_u64`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:204:14 | LL | let _n = u128::MAX * 5; | ^^^^^^^^^^^^^ attempt to compute `u128::MAX * 5_u128`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:205:15 + | +LL | let _n = &(u128::MAX * 5); + | ^^^^^^^^^^^^^^^ attempt to compute `u128::MAX * 5_u128`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:207:14 | LL | let _n = usize::MAX * 5; | ^^^^^^^^^^^^^^ attempt to compute `usize::MAX * 5_usize`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:208:15 + | +LL | let _n = &(usize::MAX * 5); + | ^^^^^^^^^^^^^^^^ attempt to compute `usize::MAX * 5_usize`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:210:14 | LL | let _n = i8::MAX * i8::MAX; | ^^^^^^^^^^^^^^^^^ attempt to compute `i8::MAX * i8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:211:15 + | +LL | let _n = &(i8::MAX * i8::MAX); + | ^^^^^^^^^^^^^^^^^^^ attempt to compute `i8::MAX * i8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:213:14 | LL | let _n = i16::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `i16::MAX * 5_i16`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:214:15 + | +LL | let _n = &(i16::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `i16::MAX * 5_i16`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:216:14 | LL | let _n = i32::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `i32::MAX * 5_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:217:15 + | +LL | let _n = &(i32::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `i32::MAX * 5_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:219:14 | LL | let _n = i64::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `i64::MAX * 5_i64`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:220:15 + | +LL | let _n = &(i64::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `i64::MAX * 5_i64`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:222:14 | LL | let _n = i128::MAX * 5; | ^^^^^^^^^^^^^ attempt to compute `i128::MAX * 5_i128`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:223:15 + | +LL | let _n = &(i128::MAX * 5); + | ^^^^^^^^^^^^^^^ attempt to compute `i128::MAX * 5_i128`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:225:14 | LL | let _n = isize::MAX * 5; | ^^^^^^^^^^^^^^ attempt to compute `isize::MAX * 5_isize`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:226:15 + | +LL | let _n = &(isize::MAX * 5); + | ^^^^^^^^^^^^^^^^ attempt to compute `isize::MAX * 5_isize`, which would overflow + error: this operation will panic at runtime --> $DIR/lint-overflowing-ops.rs:230:14 | diff --git a/tests/ui/lint/lint-overflowing-ops.opt.stderr b/tests/ui/lint/lint-overflowing-ops.opt.stderr index 1b7b73cec38d5..c85031fa8983b 100644 --- a/tests/ui/lint/lint-overflowing-ops.opt.stderr +++ b/tests/ui/lint/lint-overflowing-ops.opt.stderr @@ -11,346 +11,64 @@ LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:226:15 - | -LL | let _n = &(isize::MAX * 5); - | ^^^^^^^^^^^^^^^^ attempt to compute `isize::MAX * 5_isize`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:223:15 - | -LL | let _n = &(i128::MAX * 5); - | ^^^^^^^^^^^^^^^ attempt to compute `i128::MAX * 5_i128`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:220:15 - | -LL | let _n = &(i64::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `i64::MAX * 5_i64`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:217:15 - | -LL | let _n = &(i32::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `i32::MAX * 5_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:214:15 - | -LL | let _n = &(i16::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `i16::MAX * 5_i16`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:211:15 - | -LL | let _n = &(i8::MAX * i8::MAX); - | ^^^^^^^^^^^^^^^^^^^ attempt to compute `i8::MAX * i8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:208:15 - | -LL | let _n = &(usize::MAX * 5); - | ^^^^^^^^^^^^^^^^ attempt to compute `usize::MAX * 5_usize`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:205:15 - | -LL | let _n = &(u128::MAX * 5); - | ^^^^^^^^^^^^^^^ attempt to compute `u128::MAX * 5_u128`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:202:15 - | -LL | let _n = &(u64::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `u64::MAX * 5_u64`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:199:15 - | -LL | let _n = &(u32::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `u32::MAX * 5_u32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:196:15 - | -LL | let _n = &(u16::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `u16::MAX * 5_u16`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:193:15 - | -LL | let _n = &(u8::MAX * 5); - | ^^^^^^^^^^^^^ attempt to compute `u8::MAX * 5_u8`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:188:15 - | -LL | let _n = &(-i8::MIN); - | ^^^^^^^^^^ attempt to negate `i8::MIN`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:185:15 - | -LL | let _n = &(1usize - 5); - | ^^^^^^^^^^^^ attempt to compute `1_usize - 5_usize`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:182:15 - | -LL | let _n = &(-5isize - isize::MAX); - | ^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_isize - isize::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:179:15 - | -LL | let _n = &(-5i128 - i128::MAX); - | ^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i128 - i128::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:176:15 - | -LL | let _n = &(-5i64 - i64::MAX); - | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i64 - i64::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:173:15 - | -LL | let _n = &(-5i32 - i32::MAX); - | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:170:15 - | -LL | let _n = &(-5i16 - i16::MAX); - | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i16 - i16::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:167:15 - | -LL | let _n = &(-5i8 - i8::MAX); - | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i8 - i8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:164:15 - | -LL | let _n = &(1u128 - 5); - | ^^^^^^^^^^^ attempt to compute `1_u128 - 5_u128`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:161:15 - | -LL | let _n = &(1u64 - 5); - | ^^^^^^^^^^ attempt to compute `1_u64 - 5_u64`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:158:15 - | -LL | let _n = &(1u32 - 5); - | ^^^^^^^^^^ attempt to compute `1_u32 - 5_u32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:155:15 - | -LL | let _n = &(1u16 - 5); - | ^^^^^^^^^^ attempt to compute `1_u16 - 5_u16`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:152:15 - | -LL | let _n = &(1u8 - 5); - | ^^^^^^^^^ attempt to compute `1_u8 - 5_u8`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:147:15 - | -LL | let _n = &(1usize + usize::MAX); - | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_usize + usize::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:144:15 - | -LL | let _n = &(1isize + isize::MAX); - | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_isize + isize::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:141:15 - | -LL | let _n = &(1i128 + i128::MAX); - | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_i128 + i128::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:138:15 - | -LL | let _n = &(1i64 + i64::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i64 + i64::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:135:15 - | -LL | let _n = &(1i32 + i32::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:132:15 - | -LL | let _n = &(1i16 + i16::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i16 + i16::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:129:15 - | -LL | let _n = &(1i8 + i8::MAX); - | ^^^^^^^^^^^^^^^ attempt to compute `1_i8 + i8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:126:15 - | -LL | let _n = &(1u128 + u128::MAX); - | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_u128 + u128::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:123:15 - | -LL | let _n = &(1u64 + u64::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u64 + u64::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:120:15 - | -LL | let _n = &(1u32 + u32::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u32 + u32::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:117:15 - | -LL | let _n = &(1u16 + u16::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u16 + u16::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:114:15 - | -LL | let _n = &(1u8 + u8::MAX); - | ^^^^^^^^^^^^^^^ attempt to compute `1_u8 + u8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:110:15 - | -LL | let _n = &(1i64 >> [64][0]); - | ^^^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:107:15 - | -LL | let _n = &(1_usize >> BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:104:15 - | -LL | let _n = &(1_isize >> BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:101:15 - | -LL | let _n = &(1i128 >> 128); - | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:98:15 - | -LL | let _n = &(1i64 >> 64); - | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:95:15 - | -LL | let _n = &(1i32 >> 32); - | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:92:15 - | -LL | let _n = &(1i16 >> 16); - | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:89:15 - | -LL | let _n = &(1i8 >> 8); - | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:86:15 + --> $DIR/lint-overflowing-ops.rs:29:15 | -LL | let _n = &(1u128 >> 128); - | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow +LL | let _n = &(1u8 << 8); + | ^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:83:15 + --> $DIR/lint-overflowing-ops.rs:31:14 | -LL | let _n = &(1u64 >> 64); - | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +LL | let _n = 1u16 << 16; + | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:80:15 + --> $DIR/lint-overflowing-ops.rs:32:15 | -LL | let _n = &(1u32 >> 32); - | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +LL | let _n = &(1u16 << 16); + | ^^^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:77:15 + --> $DIR/lint-overflowing-ops.rs:34:14 | -LL | let _n = &(1u16 >> 16); - | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +LL | let _n = 1u32 << 32; + | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:74:15 + --> $DIR/lint-overflowing-ops.rs:35:15 | -LL | let _n = &(1u8 >> 8); - | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +LL | let _n = &(1u32 << 32); + | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:65:15 + --> $DIR/lint-overflowing-ops.rs:37:14 | -LL | let _n = &(1 << -1); - | ^^^^^^^^^ attempt to shift left by `-1_i32`, which would overflow +LL | let _n = 1u64 << 64; + | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:62:15 + --> $DIR/lint-overflowing-ops.rs:38:15 | -LL | let _n = &(1_usize << BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +LL | let _n = &(1u64 << 64); + | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:59:15 + --> $DIR/lint-overflowing-ops.rs:40:14 | -LL | let _n = &(1_isize << BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +LL | let _n = 1u128 << 128; + | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:56:15 + --> $DIR/lint-overflowing-ops.rs:41:15 | -LL | let _n = &(1i128 << 128); +LL | let _n = &(1u128 << 128); | ^^^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:53:15 - | -LL | let _n = &(1i64 << 64); - | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:50:15 - | -LL | let _n = &(1i32 << 32); - | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:47:15 + --> $DIR/lint-overflowing-ops.rs:43:14 | -LL | let _n = &(1i16 << 16); - | ^^^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow +LL | let _n = 1i8 << 8; + | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:44:15 @@ -359,100 +77,76 @@ LL | let _n = &(1i8 << 8); | ^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:41:15 - | -LL | let _n = &(1u128 << 128); - | ^^^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:38:15 - | -LL | let _n = &(1u64 << 64); - | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:35:15 + --> $DIR/lint-overflowing-ops.rs:46:14 | -LL | let _n = &(1u32 << 32); - | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow +LL | let _n = 1i16 << 16; + | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:32:15 + --> $DIR/lint-overflowing-ops.rs:47:15 | -LL | let _n = &(1u16 << 16); +LL | let _n = &(1i16 << 16); | ^^^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:29:15 - | -LL | let _n = &(1u8 << 8); - | ^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:31:14 - | -LL | let _n = 1u16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:34:14 + --> $DIR/lint-overflowing-ops.rs:49:14 | -LL | let _n = 1u32 << 32; +LL | let _n = 1i32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:37:14 + --> $DIR/lint-overflowing-ops.rs:50:15 | -LL | let _n = 1u64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow +LL | let _n = &(1i32 << 32); + | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:40:14 + --> $DIR/lint-overflowing-ops.rs:52:14 | -LL | let _n = 1u128 << 128; - | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow +LL | let _n = 1i64 << 64; + | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:43:14 + --> $DIR/lint-overflowing-ops.rs:53:15 | -LL | let _n = 1i8 << 8; - | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow +LL | let _n = &(1i64 << 64); + | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:46:14 + --> $DIR/lint-overflowing-ops.rs:55:14 | -LL | let _n = 1i16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow +LL | let _n = 1i128 << 128; + | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:49:14 + --> $DIR/lint-overflowing-ops.rs:56:15 | -LL | let _n = 1i32 << 32; - | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow +LL | let _n = &(1i128 << 128); + | ^^^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:52:14 + --> $DIR/lint-overflowing-ops.rs:58:14 | -LL | let _n = 1i64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow +LL | let _n = 1_isize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:55:14 + --> $DIR/lint-overflowing-ops.rs:59:15 | -LL | let _n = 1i128 << 128; - | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow +LL | let _n = &(1_isize << BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:58:14 + --> $DIR/lint-overflowing-ops.rs:61:14 | -LL | let _n = 1_isize << BITS; +LL | let _n = 1_usize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:61:14 + --> $DIR/lint-overflowing-ops.rs:62:15 | -LL | let _n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +LL | let _n = &(1_usize << BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:64:14 @@ -460,6 +154,12 @@ error: this arithmetic operation will overflow LL | let _n = 1 << -1; | ^^^^^^^ attempt to shift left by `-1_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:65:15 + | +LL | let _n = &(1 << -1); + | ^^^^^^^^^ attempt to shift left by `-1_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:69:14 | @@ -484,47 +184,95 @@ error: this arithmetic operation will overflow LL | let _n = 1u8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:74:15 + | +LL | let _n = &(1u8 >> 8); + | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:76:14 | LL | let _n = 1u16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:77:15 + | +LL | let _n = &(1u16 >> 16); + | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:79:14 | LL | let _n = 1u32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:80:15 + | +LL | let _n = &(1u32 >> 32); + | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:82:14 | LL | let _n = 1u64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:83:15 + | +LL | let _n = &(1u64 >> 64); + | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:85:14 | LL | let _n = 1u128 >> 128; | ^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:86:15 + | +LL | let _n = &(1u128 >> 128); + | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:88:14 | LL | let _n = 1i8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:89:15 + | +LL | let _n = &(1i8 >> 8); + | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:91:14 | LL | let _n = 1i16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:92:15 + | +LL | let _n = &(1i16 >> 16); + | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:94:14 | -LL | let _n = 1i32 >> 32; - | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +LL | let _n = 1i32 >> 32; + | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:95:15 + | +LL | let _n = &(1i32 >> 32); + | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:97:14 @@ -532,252 +280,504 @@ error: this arithmetic operation will overflow LL | let _n = 1i64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:98:15 + | +LL | let _n = &(1i64 >> 64); + | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:100:14 | LL | let _n = 1i128 >> 128; | ^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:101:15 + | +LL | let _n = &(1i128 >> 128); + | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:103:14 | LL | let _n = 1_isize >> BITS; | ^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:104:15 + | +LL | let _n = &(1_isize >> BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:106:14 | LL | let _n = 1_usize >> BITS; | ^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:107:15 + | +LL | let _n = &(1_usize >> BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:109:14 | LL | let _n = 1i64 >> [64][0]; | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:110:15 + | +LL | let _n = &(1i64 >> [64][0]); + | ^^^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:113:14 | LL | let _n = 1u8 + u8::MAX; | ^^^^^^^^^^^^^ attempt to compute `1_u8 + u8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:114:15 + | +LL | let _n = &(1u8 + u8::MAX); + | ^^^^^^^^^^^^^^^ attempt to compute `1_u8 + u8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:116:14 | LL | let _n = 1u16 + u16::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_u16 + u16::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:117:15 + | +LL | let _n = &(1u16 + u16::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u16 + u16::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:119:14 | LL | let _n = 1u32 + u32::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_u32 + u32::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:120:15 + | +LL | let _n = &(1u32 + u32::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u32 + u32::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:122:14 | LL | let _n = 1u64 + u64::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_u64 + u64::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:123:15 + | +LL | let _n = &(1u64 + u64::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u64 + u64::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:125:14 | LL | let _n = 1u128 + u128::MAX; | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u128 + u128::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:126:15 + | +LL | let _n = &(1u128 + u128::MAX); + | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_u128 + u128::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:128:14 | LL | let _n = 1i8 + i8::MAX; | ^^^^^^^^^^^^^ attempt to compute `1_i8 + i8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:129:15 + | +LL | let _n = &(1i8 + i8::MAX); + | ^^^^^^^^^^^^^^^ attempt to compute `1_i8 + i8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:131:14 | LL | let _n = 1i16 + i16::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_i16 + i16::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:132:15 + | +LL | let _n = &(1i16 + i16::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i16 + i16::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:134:14 | LL | let _n = 1i32 + i32::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:135:15 + | +LL | let _n = &(1i32 + i32::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:137:14 | LL | let _n = 1i64 + i64::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_i64 + i64::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:138:15 + | +LL | let _n = &(1i64 + i64::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i64 + i64::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:140:14 | LL | let _n = 1i128 + i128::MAX; | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i128 + i128::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:141:15 + | +LL | let _n = &(1i128 + i128::MAX); + | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_i128 + i128::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:143:14 | LL | let _n = 1isize + isize::MAX; | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_isize + isize::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:144:15 + | +LL | let _n = &(1isize + isize::MAX); + | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_isize + isize::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:146:14 | LL | let _n = 1usize + usize::MAX; | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_usize + usize::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:147:15 + | +LL | let _n = &(1usize + usize::MAX); + | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_usize + usize::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:151:14 | LL | let _n = 1u8 - 5; | ^^^^^^^ attempt to compute `1_u8 - 5_u8`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:152:15 + | +LL | let _n = &(1u8 - 5); + | ^^^^^^^^^ attempt to compute `1_u8 - 5_u8`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:154:14 | LL | let _n = 1u16 - 5; | ^^^^^^^^ attempt to compute `1_u16 - 5_u16`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:155:15 + | +LL | let _n = &(1u16 - 5); + | ^^^^^^^^^^ attempt to compute `1_u16 - 5_u16`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:157:14 | LL | let _n = 1u32 - 5; | ^^^^^^^^ attempt to compute `1_u32 - 5_u32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:158:15 + | +LL | let _n = &(1u32 - 5); + | ^^^^^^^^^^ attempt to compute `1_u32 - 5_u32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:160:14 | LL | let _n = 1u64 - 5 ; | ^^^^^^^^ attempt to compute `1_u64 - 5_u64`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:161:15 + | +LL | let _n = &(1u64 - 5); + | ^^^^^^^^^^ attempt to compute `1_u64 - 5_u64`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:163:14 | LL | let _n = 1u128 - 5 ; | ^^^^^^^^^ attempt to compute `1_u128 - 5_u128`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:164:15 + | +LL | let _n = &(1u128 - 5); + | ^^^^^^^^^^^ attempt to compute `1_u128 - 5_u128`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:166:14 | LL | let _n = -5i8 - i8::MAX; | ^^^^^^^^^^^^^^ attempt to compute `-5_i8 - i8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:167:15 + | +LL | let _n = &(-5i8 - i8::MAX); + | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i8 - i8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:169:14 | LL | let _n = -5i16 - i16::MAX; | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i16 - i16::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:170:15 + | +LL | let _n = &(-5i16 - i16::MAX); + | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i16 - i16::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:172:14 | LL | let _n = -5i32 - i32::MAX; | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:173:15 + | +LL | let _n = &(-5i32 - i32::MAX); + | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:175:14 | LL | let _n = -5i64 - i64::MAX; | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i64 - i64::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:176:15 + | +LL | let _n = &(-5i64 - i64::MAX); + | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i64 - i64::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:178:14 | LL | let _n = -5i128 - i128::MAX; | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i128 - i128::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:179:15 + | +LL | let _n = &(-5i128 - i128::MAX); + | ^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i128 - i128::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:181:14 | LL | let _n = -5isize - isize::MAX; | ^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_isize - isize::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:182:15 + | +LL | let _n = &(-5isize - isize::MAX); + | ^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_isize - isize::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:184:14 | LL | let _n = 1usize - 5; | ^^^^^^^^^^ attempt to compute `1_usize - 5_usize`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:185:15 + | +LL | let _n = &(1usize - 5); + | ^^^^^^^^^^^^ attempt to compute `1_usize - 5_usize`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:187:14 | LL | let _n = -i8::MIN; | ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:188:15 + | +LL | let _n = &(-i8::MIN); + | ^^^^^^^^^^ attempt to negate `i8::MIN`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:192:14 | LL | let _n = u8::MAX * 5; | ^^^^^^^^^^^ attempt to compute `u8::MAX * 5_u8`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:193:15 + | +LL | let _n = &(u8::MAX * 5); + | ^^^^^^^^^^^^^ attempt to compute `u8::MAX * 5_u8`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:195:14 | LL | let _n = u16::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `u16::MAX * 5_u16`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:196:15 + | +LL | let _n = &(u16::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `u16::MAX * 5_u16`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:198:14 | LL | let _n = u32::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `u32::MAX * 5_u32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:199:15 + | +LL | let _n = &(u32::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `u32::MAX * 5_u32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:201:14 | LL | let _n = u64::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `u64::MAX * 5_u64`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:202:15 + | +LL | let _n = &(u64::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `u64::MAX * 5_u64`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:204:14 | LL | let _n = u128::MAX * 5; | ^^^^^^^^^^^^^ attempt to compute `u128::MAX * 5_u128`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:205:15 + | +LL | let _n = &(u128::MAX * 5); + | ^^^^^^^^^^^^^^^ attempt to compute `u128::MAX * 5_u128`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:207:14 | LL | let _n = usize::MAX * 5; | ^^^^^^^^^^^^^^ attempt to compute `usize::MAX * 5_usize`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:208:15 + | +LL | let _n = &(usize::MAX * 5); + | ^^^^^^^^^^^^^^^^ attempt to compute `usize::MAX * 5_usize`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:210:14 | LL | let _n = i8::MAX * i8::MAX; | ^^^^^^^^^^^^^^^^^ attempt to compute `i8::MAX * i8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:211:15 + | +LL | let _n = &(i8::MAX * i8::MAX); + | ^^^^^^^^^^^^^^^^^^^ attempt to compute `i8::MAX * i8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:213:14 | LL | let _n = i16::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `i16::MAX * 5_i16`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:214:15 + | +LL | let _n = &(i16::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `i16::MAX * 5_i16`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:216:14 | LL | let _n = i32::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `i32::MAX * 5_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:217:15 + | +LL | let _n = &(i32::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `i32::MAX * 5_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:219:14 | LL | let _n = i64::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `i64::MAX * 5_i64`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:220:15 + | +LL | let _n = &(i64::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `i64::MAX * 5_i64`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:222:14 | LL | let _n = i128::MAX * 5; | ^^^^^^^^^^^^^ attempt to compute `i128::MAX * 5_i128`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:223:15 + | +LL | let _n = &(i128::MAX * 5); + | ^^^^^^^^^^^^^^^ attempt to compute `i128::MAX * 5_i128`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:225:14 | LL | let _n = isize::MAX * 5; | ^^^^^^^^^^^^^^ attempt to compute `isize::MAX * 5_isize`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:226:15 + | +LL | let _n = &(isize::MAX * 5); + | ^^^^^^^^^^^^^^^^ attempt to compute `isize::MAX * 5_isize`, which would overflow + error: this operation will panic at runtime --> $DIR/lint-overflowing-ops.rs:230:14 | diff --git a/tests/ui/lint/lint-overflowing-ops.opt_with_overflow_checks.stderr b/tests/ui/lint/lint-overflowing-ops.opt_with_overflow_checks.stderr index 1b7b73cec38d5..c85031fa8983b 100644 --- a/tests/ui/lint/lint-overflowing-ops.opt_with_overflow_checks.stderr +++ b/tests/ui/lint/lint-overflowing-ops.opt_with_overflow_checks.stderr @@ -11,346 +11,64 @@ LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:226:15 - | -LL | let _n = &(isize::MAX * 5); - | ^^^^^^^^^^^^^^^^ attempt to compute `isize::MAX * 5_isize`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:223:15 - | -LL | let _n = &(i128::MAX * 5); - | ^^^^^^^^^^^^^^^ attempt to compute `i128::MAX * 5_i128`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:220:15 - | -LL | let _n = &(i64::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `i64::MAX * 5_i64`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:217:15 - | -LL | let _n = &(i32::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `i32::MAX * 5_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:214:15 - | -LL | let _n = &(i16::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `i16::MAX * 5_i16`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:211:15 - | -LL | let _n = &(i8::MAX * i8::MAX); - | ^^^^^^^^^^^^^^^^^^^ attempt to compute `i8::MAX * i8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:208:15 - | -LL | let _n = &(usize::MAX * 5); - | ^^^^^^^^^^^^^^^^ attempt to compute `usize::MAX * 5_usize`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:205:15 - | -LL | let _n = &(u128::MAX * 5); - | ^^^^^^^^^^^^^^^ attempt to compute `u128::MAX * 5_u128`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:202:15 - | -LL | let _n = &(u64::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `u64::MAX * 5_u64`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:199:15 - | -LL | let _n = &(u32::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `u32::MAX * 5_u32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:196:15 - | -LL | let _n = &(u16::MAX * 5); - | ^^^^^^^^^^^^^^ attempt to compute `u16::MAX * 5_u16`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:193:15 - | -LL | let _n = &(u8::MAX * 5); - | ^^^^^^^^^^^^^ attempt to compute `u8::MAX * 5_u8`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:188:15 - | -LL | let _n = &(-i8::MIN); - | ^^^^^^^^^^ attempt to negate `i8::MIN`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:185:15 - | -LL | let _n = &(1usize - 5); - | ^^^^^^^^^^^^ attempt to compute `1_usize - 5_usize`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:182:15 - | -LL | let _n = &(-5isize - isize::MAX); - | ^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_isize - isize::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:179:15 - | -LL | let _n = &(-5i128 - i128::MAX); - | ^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i128 - i128::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:176:15 - | -LL | let _n = &(-5i64 - i64::MAX); - | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i64 - i64::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:173:15 - | -LL | let _n = &(-5i32 - i32::MAX); - | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:170:15 - | -LL | let _n = &(-5i16 - i16::MAX); - | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i16 - i16::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:167:15 - | -LL | let _n = &(-5i8 - i8::MAX); - | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i8 - i8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:164:15 - | -LL | let _n = &(1u128 - 5); - | ^^^^^^^^^^^ attempt to compute `1_u128 - 5_u128`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:161:15 - | -LL | let _n = &(1u64 - 5); - | ^^^^^^^^^^ attempt to compute `1_u64 - 5_u64`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:158:15 - | -LL | let _n = &(1u32 - 5); - | ^^^^^^^^^^ attempt to compute `1_u32 - 5_u32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:155:15 - | -LL | let _n = &(1u16 - 5); - | ^^^^^^^^^^ attempt to compute `1_u16 - 5_u16`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:152:15 - | -LL | let _n = &(1u8 - 5); - | ^^^^^^^^^ attempt to compute `1_u8 - 5_u8`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:147:15 - | -LL | let _n = &(1usize + usize::MAX); - | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_usize + usize::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:144:15 - | -LL | let _n = &(1isize + isize::MAX); - | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_isize + isize::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:141:15 - | -LL | let _n = &(1i128 + i128::MAX); - | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_i128 + i128::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:138:15 - | -LL | let _n = &(1i64 + i64::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i64 + i64::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:135:15 - | -LL | let _n = &(1i32 + i32::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:132:15 - | -LL | let _n = &(1i16 + i16::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i16 + i16::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:129:15 - | -LL | let _n = &(1i8 + i8::MAX); - | ^^^^^^^^^^^^^^^ attempt to compute `1_i8 + i8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:126:15 - | -LL | let _n = &(1u128 + u128::MAX); - | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_u128 + u128::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:123:15 - | -LL | let _n = &(1u64 + u64::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u64 + u64::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:120:15 - | -LL | let _n = &(1u32 + u32::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u32 + u32::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:117:15 - | -LL | let _n = &(1u16 + u16::MAX); - | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u16 + u16::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:114:15 - | -LL | let _n = &(1u8 + u8::MAX); - | ^^^^^^^^^^^^^^^ attempt to compute `1_u8 + u8::MAX`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:110:15 - | -LL | let _n = &(1i64 >> [64][0]); - | ^^^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:107:15 - | -LL | let _n = &(1_usize >> BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:104:15 - | -LL | let _n = &(1_isize >> BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:101:15 - | -LL | let _n = &(1i128 >> 128); - | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:98:15 - | -LL | let _n = &(1i64 >> 64); - | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:95:15 - | -LL | let _n = &(1i32 >> 32); - | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:92:15 - | -LL | let _n = &(1i16 >> 16); - | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:89:15 - | -LL | let _n = &(1i8 >> 8); - | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:86:15 + --> $DIR/lint-overflowing-ops.rs:29:15 | -LL | let _n = &(1u128 >> 128); - | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow +LL | let _n = &(1u8 << 8); + | ^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:83:15 + --> $DIR/lint-overflowing-ops.rs:31:14 | -LL | let _n = &(1u64 >> 64); - | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +LL | let _n = 1u16 << 16; + | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:80:15 + --> $DIR/lint-overflowing-ops.rs:32:15 | -LL | let _n = &(1u32 >> 32); - | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +LL | let _n = &(1u16 << 16); + | ^^^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:77:15 + --> $DIR/lint-overflowing-ops.rs:34:14 | -LL | let _n = &(1u16 >> 16); - | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +LL | let _n = 1u32 << 32; + | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:74:15 + --> $DIR/lint-overflowing-ops.rs:35:15 | -LL | let _n = &(1u8 >> 8); - | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +LL | let _n = &(1u32 << 32); + | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:65:15 + --> $DIR/lint-overflowing-ops.rs:37:14 | -LL | let _n = &(1 << -1); - | ^^^^^^^^^ attempt to shift left by `-1_i32`, which would overflow +LL | let _n = 1u64 << 64; + | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:62:15 + --> $DIR/lint-overflowing-ops.rs:38:15 | -LL | let _n = &(1_usize << BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +LL | let _n = &(1u64 << 64); + | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:59:15 + --> $DIR/lint-overflowing-ops.rs:40:14 | -LL | let _n = &(1_isize << BITS); - | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +LL | let _n = 1u128 << 128; + | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:56:15 + --> $DIR/lint-overflowing-ops.rs:41:15 | -LL | let _n = &(1i128 << 128); +LL | let _n = &(1u128 << 128); | ^^^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:53:15 - | -LL | let _n = &(1i64 << 64); - | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:50:15 - | -LL | let _n = &(1i32 << 32); - | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:47:15 + --> $DIR/lint-overflowing-ops.rs:43:14 | -LL | let _n = &(1i16 << 16); - | ^^^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow +LL | let _n = 1i8 << 8; + | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:44:15 @@ -359,100 +77,76 @@ LL | let _n = &(1i8 << 8); | ^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:41:15 - | -LL | let _n = &(1u128 << 128); - | ^^^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:38:15 - | -LL | let _n = &(1u64 << 64); - | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:35:15 + --> $DIR/lint-overflowing-ops.rs:46:14 | -LL | let _n = &(1u32 << 32); - | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow +LL | let _n = 1i16 << 16; + | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:32:15 + --> $DIR/lint-overflowing-ops.rs:47:15 | -LL | let _n = &(1u16 << 16); +LL | let _n = &(1i16 << 16); | ^^^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:29:15 - | -LL | let _n = &(1u8 << 8); - | ^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:31:14 - | -LL | let _n = 1u16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:34:14 + --> $DIR/lint-overflowing-ops.rs:49:14 | -LL | let _n = 1u32 << 32; +LL | let _n = 1i32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:37:14 + --> $DIR/lint-overflowing-ops.rs:50:15 | -LL | let _n = 1u64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow +LL | let _n = &(1i32 << 32); + | ^^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:40:14 + --> $DIR/lint-overflowing-ops.rs:52:14 | -LL | let _n = 1u128 << 128; - | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow +LL | let _n = 1i64 << 64; + | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:43:14 + --> $DIR/lint-overflowing-ops.rs:53:15 | -LL | let _n = 1i8 << 8; - | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow +LL | let _n = &(1i64 << 64); + | ^^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:46:14 + --> $DIR/lint-overflowing-ops.rs:55:14 | -LL | let _n = 1i16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow +LL | let _n = 1i128 << 128; + | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:49:14 + --> $DIR/lint-overflowing-ops.rs:56:15 | -LL | let _n = 1i32 << 32; - | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow +LL | let _n = &(1i128 << 128); + | ^^^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:52:14 + --> $DIR/lint-overflowing-ops.rs:58:14 | -LL | let _n = 1i64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow +LL | let _n = 1_isize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:55:14 + --> $DIR/lint-overflowing-ops.rs:59:15 | -LL | let _n = 1i128 << 128; - | ^^^^^^^^^^^^ attempt to shift left by `128_i32`, which would overflow +LL | let _n = &(1_isize << BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:58:14 + --> $DIR/lint-overflowing-ops.rs:61:14 | -LL | let _n = 1_isize << BITS; +LL | let _n = 1_usize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow - --> $DIR/lint-overflowing-ops.rs:61:14 + --> $DIR/lint-overflowing-ops.rs:62:15 | -LL | let _n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +LL | let _n = &(1_usize << BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:64:14 @@ -460,6 +154,12 @@ error: this arithmetic operation will overflow LL | let _n = 1 << -1; | ^^^^^^^ attempt to shift left by `-1_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:65:15 + | +LL | let _n = &(1 << -1); + | ^^^^^^^^^ attempt to shift left by `-1_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:69:14 | @@ -484,47 +184,95 @@ error: this arithmetic operation will overflow LL | let _n = 1u8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:74:15 + | +LL | let _n = &(1u8 >> 8); + | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:76:14 | LL | let _n = 1u16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:77:15 + | +LL | let _n = &(1u16 >> 16); + | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:79:14 | LL | let _n = 1u32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:80:15 + | +LL | let _n = &(1u32 >> 32); + | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:82:14 | LL | let _n = 1u64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:83:15 + | +LL | let _n = &(1u64 >> 64); + | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:85:14 | LL | let _n = 1u128 >> 128; | ^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:86:15 + | +LL | let _n = &(1u128 >> 128); + | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:88:14 | LL | let _n = 1i8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:89:15 + | +LL | let _n = &(1i8 >> 8); + | ^^^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:91:14 | LL | let _n = 1i16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:92:15 + | +LL | let _n = &(1i16 >> 16); + | ^^^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:94:14 | -LL | let _n = 1i32 >> 32; - | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +LL | let _n = 1i32 >> 32; + | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:95:15 + | +LL | let _n = &(1i32 >> 32); + | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:97:14 @@ -532,252 +280,504 @@ error: this arithmetic operation will overflow LL | let _n = 1i64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:98:15 + | +LL | let _n = &(1i64 >> 64); + | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:100:14 | LL | let _n = 1i128 >> 128; | ^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:101:15 + | +LL | let _n = &(1i128 >> 128); + | ^^^^^^^^^^^^^^ attempt to shift right by `128_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:103:14 | LL | let _n = 1_isize >> BITS; | ^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:104:15 + | +LL | let _n = &(1_isize >> BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:106:14 | LL | let _n = 1_usize >> BITS; | ^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:107:15 + | +LL | let _n = &(1_usize >> BITS); + | ^^^^^^^^^^^^^^^^^ attempt to shift right by `%BITS%`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:109:14 | LL | let _n = 1i64 >> [64][0]; | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:110:15 + | +LL | let _n = &(1i64 >> [64][0]); + | ^^^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:113:14 | LL | let _n = 1u8 + u8::MAX; | ^^^^^^^^^^^^^ attempt to compute `1_u8 + u8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:114:15 + | +LL | let _n = &(1u8 + u8::MAX); + | ^^^^^^^^^^^^^^^ attempt to compute `1_u8 + u8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:116:14 | LL | let _n = 1u16 + u16::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_u16 + u16::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:117:15 + | +LL | let _n = &(1u16 + u16::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u16 + u16::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:119:14 | LL | let _n = 1u32 + u32::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_u32 + u32::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:120:15 + | +LL | let _n = &(1u32 + u32::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u32 + u32::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:122:14 | LL | let _n = 1u64 + u64::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_u64 + u64::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:123:15 + | +LL | let _n = &(1u64 + u64::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u64 + u64::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:125:14 | LL | let _n = 1u128 + u128::MAX; | ^^^^^^^^^^^^^^^^^ attempt to compute `1_u128 + u128::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:126:15 + | +LL | let _n = &(1u128 + u128::MAX); + | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_u128 + u128::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:128:14 | LL | let _n = 1i8 + i8::MAX; | ^^^^^^^^^^^^^ attempt to compute `1_i8 + i8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:129:15 + | +LL | let _n = &(1i8 + i8::MAX); + | ^^^^^^^^^^^^^^^ attempt to compute `1_i8 + i8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:131:14 | LL | let _n = 1i16 + i16::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_i16 + i16::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:132:15 + | +LL | let _n = &(1i16 + i16::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i16 + i16::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:134:14 | LL | let _n = 1i32 + i32::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:135:15 + | +LL | let _n = &(1i32 + i32::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i32 + i32::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:137:14 | LL | let _n = 1i64 + i64::MAX; | ^^^^^^^^^^^^^^^ attempt to compute `1_i64 + i64::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:138:15 + | +LL | let _n = &(1i64 + i64::MAX); + | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i64 + i64::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:140:14 | LL | let _n = 1i128 + i128::MAX; | ^^^^^^^^^^^^^^^^^ attempt to compute `1_i128 + i128::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:141:15 + | +LL | let _n = &(1i128 + i128::MAX); + | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_i128 + i128::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:143:14 | LL | let _n = 1isize + isize::MAX; | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_isize + isize::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:144:15 + | +LL | let _n = &(1isize + isize::MAX); + | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_isize + isize::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:146:14 | LL | let _n = 1usize + usize::MAX; | ^^^^^^^^^^^^^^^^^^^ attempt to compute `1_usize + usize::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:147:15 + | +LL | let _n = &(1usize + usize::MAX); + | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_usize + usize::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:151:14 | LL | let _n = 1u8 - 5; | ^^^^^^^ attempt to compute `1_u8 - 5_u8`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:152:15 + | +LL | let _n = &(1u8 - 5); + | ^^^^^^^^^ attempt to compute `1_u8 - 5_u8`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:154:14 | LL | let _n = 1u16 - 5; | ^^^^^^^^ attempt to compute `1_u16 - 5_u16`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:155:15 + | +LL | let _n = &(1u16 - 5); + | ^^^^^^^^^^ attempt to compute `1_u16 - 5_u16`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:157:14 | LL | let _n = 1u32 - 5; | ^^^^^^^^ attempt to compute `1_u32 - 5_u32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:158:15 + | +LL | let _n = &(1u32 - 5); + | ^^^^^^^^^^ attempt to compute `1_u32 - 5_u32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:160:14 | LL | let _n = 1u64 - 5 ; | ^^^^^^^^ attempt to compute `1_u64 - 5_u64`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:161:15 + | +LL | let _n = &(1u64 - 5); + | ^^^^^^^^^^ attempt to compute `1_u64 - 5_u64`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:163:14 | LL | let _n = 1u128 - 5 ; | ^^^^^^^^^ attempt to compute `1_u128 - 5_u128`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:164:15 + | +LL | let _n = &(1u128 - 5); + | ^^^^^^^^^^^ attempt to compute `1_u128 - 5_u128`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:166:14 | LL | let _n = -5i8 - i8::MAX; | ^^^^^^^^^^^^^^ attempt to compute `-5_i8 - i8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:167:15 + | +LL | let _n = &(-5i8 - i8::MAX); + | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i8 - i8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:169:14 | LL | let _n = -5i16 - i16::MAX; | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i16 - i16::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:170:15 + | +LL | let _n = &(-5i16 - i16::MAX); + | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i16 - i16::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:172:14 | LL | let _n = -5i32 - i32::MAX; | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:173:15 + | +LL | let _n = &(-5i32 - i32::MAX); + | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i32 - i32::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:175:14 | LL | let _n = -5i64 - i64::MAX; | ^^^^^^^^^^^^^^^^ attempt to compute `-5_i64 - i64::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:176:15 + | +LL | let _n = &(-5i64 - i64::MAX); + | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i64 - i64::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:178:14 | LL | let _n = -5i128 - i128::MAX; | ^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i128 - i128::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:179:15 + | +LL | let _n = &(-5i128 - i128::MAX); + | ^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_i128 - i128::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:181:14 | LL | let _n = -5isize - isize::MAX; | ^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_isize - isize::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:182:15 + | +LL | let _n = &(-5isize - isize::MAX); + | ^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `-5_isize - isize::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:184:14 | LL | let _n = 1usize - 5; | ^^^^^^^^^^ attempt to compute `1_usize - 5_usize`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:185:15 + | +LL | let _n = &(1usize - 5); + | ^^^^^^^^^^^^ attempt to compute `1_usize - 5_usize`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:187:14 | LL | let _n = -i8::MIN; | ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:188:15 + | +LL | let _n = &(-i8::MIN); + | ^^^^^^^^^^ attempt to negate `i8::MIN`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:192:14 | LL | let _n = u8::MAX * 5; | ^^^^^^^^^^^ attempt to compute `u8::MAX * 5_u8`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:193:15 + | +LL | let _n = &(u8::MAX * 5); + | ^^^^^^^^^^^^^ attempt to compute `u8::MAX * 5_u8`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:195:14 | LL | let _n = u16::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `u16::MAX * 5_u16`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:196:15 + | +LL | let _n = &(u16::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `u16::MAX * 5_u16`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:198:14 | LL | let _n = u32::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `u32::MAX * 5_u32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:199:15 + | +LL | let _n = &(u32::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `u32::MAX * 5_u32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:201:14 | LL | let _n = u64::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `u64::MAX * 5_u64`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:202:15 + | +LL | let _n = &(u64::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `u64::MAX * 5_u64`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:204:14 | LL | let _n = u128::MAX * 5; | ^^^^^^^^^^^^^ attempt to compute `u128::MAX * 5_u128`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:205:15 + | +LL | let _n = &(u128::MAX * 5); + | ^^^^^^^^^^^^^^^ attempt to compute `u128::MAX * 5_u128`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:207:14 | LL | let _n = usize::MAX * 5; | ^^^^^^^^^^^^^^ attempt to compute `usize::MAX * 5_usize`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:208:15 + | +LL | let _n = &(usize::MAX * 5); + | ^^^^^^^^^^^^^^^^ attempt to compute `usize::MAX * 5_usize`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:210:14 | LL | let _n = i8::MAX * i8::MAX; | ^^^^^^^^^^^^^^^^^ attempt to compute `i8::MAX * i8::MAX`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:211:15 + | +LL | let _n = &(i8::MAX * i8::MAX); + | ^^^^^^^^^^^^^^^^^^^ attempt to compute `i8::MAX * i8::MAX`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:213:14 | LL | let _n = i16::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `i16::MAX * 5_i16`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:214:15 + | +LL | let _n = &(i16::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `i16::MAX * 5_i16`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:216:14 | LL | let _n = i32::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `i32::MAX * 5_i32`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:217:15 + | +LL | let _n = &(i32::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `i32::MAX * 5_i32`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:219:14 | LL | let _n = i64::MAX * 5; | ^^^^^^^^^^^^ attempt to compute `i64::MAX * 5_i64`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:220:15 + | +LL | let _n = &(i64::MAX * 5); + | ^^^^^^^^^^^^^^ attempt to compute `i64::MAX * 5_i64`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:222:14 | LL | let _n = i128::MAX * 5; | ^^^^^^^^^^^^^ attempt to compute `i128::MAX * 5_i128`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:223:15 + | +LL | let _n = &(i128::MAX * 5); + | ^^^^^^^^^^^^^^^ attempt to compute `i128::MAX * 5_i128`, which would overflow + error: this arithmetic operation will overflow --> $DIR/lint-overflowing-ops.rs:225:14 | LL | let _n = isize::MAX * 5; | ^^^^^^^^^^^^^^ attempt to compute `isize::MAX * 5_isize`, which would overflow +error: this arithmetic operation will overflow + --> $DIR/lint-overflowing-ops.rs:226:15 + | +LL | let _n = &(isize::MAX * 5); + | ^^^^^^^^^^^^^^^^ attempt to compute `isize::MAX * 5_isize`, which would overflow + error: this operation will panic at runtime --> $DIR/lint-overflowing-ops.rs:230:14 | diff --git a/tests/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr b/tests/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr index 396e149554ce8..ddbfd90fde8f0 100644 --- a/tests/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr +++ b/tests/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr @@ -14,6 +14,14 @@ LL | twice(cell, value, |a, b| invoke(a, b)); = note: number of external vids: 2 = note: where T: '?1 +note: no external requirements + --> $DIR/ty-param-closure-approximate-lower-bound.rs:23:26 + | +LL | let cell = Cell::new(&()); + | ^^^ + | + = note: defining inline constant type: generic::{promoted#0} + note: no external requirements --> $DIR/ty-param-closure-approximate-lower-bound.rs:22:1 | diff --git a/tests/ui/nll/user-annotations/promoted-annotation.stderr b/tests/ui/nll/user-annotations/promoted-annotation.stderr index ca99e53187091..5b27251bdd25b 100644 --- a/tests/ui/nll/user-annotations/promoted-annotation.stderr +++ b/tests/ui/nll/user-annotations/promoted-annotation.stderr @@ -6,7 +6,7 @@ LL | fn foo<'a>() { LL | let x = 0; | - binding `x` declared here LL | let f = &drop::<&'a i32>; - | ---------------- assignment requires that `x` is borrowed for `'a` + | ---------------- using this value as a constant requires that `x` is borrowed for `'a` LL | f(&x); | ^^ borrowed value does not live long enough LL | From 98f88b34c43b71ff7b936158ce775cbfe40ddc7e Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Tue, 28 Apr 2026 02:13:58 +0000 Subject: [PATCH 11/15] Bless mir-opt. --- ...}.SimplifyCfg-pre-optimizations.after.mir} | 4 +- ...motion_extern_static.BAR.PromoteTemps.diff | 2 +- ...}.SimplifyCfg-pre-optimizations.after.mir} | 4 +- ...motion_extern_static.FOO.PromoteTemps.diff | 2 +- .../mir-opt/const_promotion_extern_static.rs | 4 +- ...for_slices.main.GVN.32bit.panic-abort.diff | 2 +- ...or_slices.main.GVN.32bit.panic-unwind.diff | 2 +- ...for_slices.main.GVN.64bit.panic-abort.diff | 2 +- ...or_slices.main.GVN.64bit.panic-unwind.diff | 2 +- .../const_prop/ref_deref.main.GVN.diff | 2 +- .../ref_deref_project.main.GVN.diff | 2 +- .../slice_len.main.GVN.32bit.panic-abort.diff | 2 +- ...slice_len.main.GVN.32bit.panic-unwind.diff | 2 +- .../slice_len.main.GVN.64bit.panic-abort.diff | 2 +- ...slice_len.main.GVN.64bit.panic-unwind.diff | 2 +- ...l.borrow_in_loop.CopyProp.panic-abort.diff | 2 +- ....borrow_in_loop.CopyProp.panic-unwind.diff | 2 +- ...n.DataflowConstProp.32bit.panic-abort.diff | 2 +- ....DataflowConstProp.32bit.panic-unwind.diff | 2 +- ...n.DataflowConstProp.64bit.panic-abort.diff | 2 +- ....DataflowConstProp.64bit.panic-unwind.diff | 2 +- ...debuginfo_locals.ReferencePropagation.diff | 2 +- ...sts.invalid_debuginfo.SingleUseConsts.diff | 6 +-- ...complex_case.main.Derefer.panic-abort.diff | 2 +- ...omplex_case.main.Derefer.panic-unwind.diff | 2 +- ...n.wide_ptr_provenance.GVN.panic-abort.diff | 4 +- ....wide_ptr_provenance.GVN.panic-unwind.diff | 4 +- ...e_ptr_same_provenance.GVN.panic-abort.diff | 2 +- ..._ptr_same_provenance.GVN.panic-unwind.diff | 2 +- .../gvn_uninhabited.f.GVN.panic-abort.diff | 2 +- .../gvn_uninhabited.f.GVN.panic-unwind.diff | 2 +- .../inline/inline_retag.bar.Inline.after.mir | 4 +- ...issue_106141.outer.Inline.panic-abort.diff | 2 +- ...ssue_106141.outer.Inline.panic-unwind.diff | 2 +- ...trait_body.Trait-a.Inline.panic-abort.diff | 2 +- ...rait_body.Trait-a.Inline.panic-unwind.diff | 2 +- ...trait_body.Trait-b.Inline.panic-abort.diff | 2 +- ...rait_body.Trait-b.Inline.panic-unwind.diff | 2 +- ..._conditions.JumpThreading.panic-abort.diff | 4 +- ...conditions.JumpThreading.panic-unwind.diff | 4 +- ...criminant.LowerIntrinsics.panic-abort.diff | 6 +-- ...riminant.LowerIntrinsics.panic-unwind.diff | 6 +-- ...ated_loop.PreCodegen.after.panic-abort.mir | 36 ++++++++------- ...ward_loop.PreCodegen.after.panic-abort.mir | 29 ++++++------ ...ange_loop.PreCodegen.after.panic-abort.mir | 6 +++ ...erse_loop.PreCodegen.after.panic-abort.mir | 28 ++++++------ ..._is_empty.PreCodegen.after.panic-abort.mir | 12 ++--- ...next_back.PreCodegen.after.panic-abort.mir | 16 +++---- ...iter_next.PreCodegen.after.panic-abort.mir | 44 +++++++++++-------- ...e_prop.debuginfo.ReferencePropagation.diff | 6 +-- ...fg-pre-optimizations.after.panic-abort.mir | 2 +- ...g-pre-optimizations.after.panic-unwind.mir | 2 +- ...fg-pre-optimizations.after.panic-abort.mir | 2 +- ...g-pre-optimizations.after.panic-unwind.mir | 2 +- 54 files changed, 156 insertions(+), 141 deletions(-) rename tests/mir-opt/{const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-pre-optimizations.after.mir => const_promotion_extern_static.BAR-{promoted#0}.SimplifyCfg-pre-optimizations.after.mir} (70%) rename tests/mir-opt/{const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-pre-optimizations.after.mir => const_promotion_extern_static.FOO-{promoted#0}.SimplifyCfg-pre-optimizations.after.mir} (71%) diff --git a/tests/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-pre-optimizations.after.mir b/tests/mir-opt/const_promotion_extern_static.BAR-{promoted#0}.SimplifyCfg-pre-optimizations.after.mir similarity index 70% rename from tests/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-pre-optimizations.after.mir rename to tests/mir-opt/const_promotion_extern_static.BAR-{promoted#0}.SimplifyCfg-pre-optimizations.after.mir index 344851bb08839..056f62e8b5fe6 100644 --- a/tests/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-pre-optimizations.after.mir +++ b/tests/mir-opt/const_promotion_extern_static.BAR-{promoted#0}.SimplifyCfg-pre-optimizations.after.mir @@ -1,6 +1,6 @@ -// MIR for `BAR::promoted[0]` after SimplifyCfg-pre-optimizations +// MIR for `BAR::{promoted#0}` after SimplifyCfg-pre-optimizations -const BAR::promoted[0]: &[&i32; 1] = { +const BAR::{promoted#0}: &[&i32; 1] = { let mut _0: &[&i32; 1]; let mut _1: [&i32; 1]; let mut _2: &i32; diff --git a/tests/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff b/tests/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff index 5f8f84244af6c..c21ccd90ebee2 100644 --- a/tests/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff +++ b/tests/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff @@ -20,7 +20,7 @@ - _4 = &(*_5); - _3 = [move _4]; - _2 = &_3; -+ _6 = const BAR::promoted[0]; ++ _6 = const BAR::{promoted#0}; + _2 = &(*_6); _1 = move _2 as &[&i32] (PointerCoercion(Unsize, Implicit)); - StorageDead(_4); diff --git a/tests/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-pre-optimizations.after.mir b/tests/mir-opt/const_promotion_extern_static.FOO-{promoted#0}.SimplifyCfg-pre-optimizations.after.mir similarity index 71% rename from tests/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-pre-optimizations.after.mir rename to tests/mir-opt/const_promotion_extern_static.FOO-{promoted#0}.SimplifyCfg-pre-optimizations.after.mir index 72cb64e275e36..24b3c442c6e59 100644 --- a/tests/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-pre-optimizations.after.mir +++ b/tests/mir-opt/const_promotion_extern_static.FOO-{promoted#0}.SimplifyCfg-pre-optimizations.after.mir @@ -1,6 +1,6 @@ -// MIR for `FOO::promoted[0]` after SimplifyCfg-pre-optimizations +// MIR for `FOO::{promoted#0}` after SimplifyCfg-pre-optimizations -const FOO::promoted[0]: &[&i32; 1] = { +const FOO::{promoted#0}: &[&i32; 1] = { let mut _0: &[&i32; 1]; let mut _1: [&i32; 1]; let mut _2: &i32; diff --git a/tests/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff b/tests/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff index 0e4eed2c028d0..f4aab638dea13 100644 --- a/tests/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff +++ b/tests/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff @@ -20,7 +20,7 @@ - _4 = &(*_5); - _3 = [move _4]; - _2 = &_3; -+ _6 = const FOO::promoted[0]; ++ _6 = const FOO::{promoted#0}; + _2 = &(*_6); _1 = move _2 as &[&i32] (PointerCoercion(Unsize, Implicit)); - StorageDead(_4); diff --git a/tests/mir-opt/const_promotion_extern_static.rs b/tests/mir-opt/const_promotion_extern_static.rs index f16a53270a97d..5cc45008e4fae 100644 --- a/tests/mir-opt/const_promotion_extern_static.rs +++ b/tests/mir-opt/const_promotion_extern_static.rs @@ -6,11 +6,11 @@ extern "C" { static Y: i32 = 42; // EMIT_MIR const_promotion_extern_static.BAR.PromoteTemps.diff -// EMIT_MIR const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-pre-optimizations.after.mir +// EMIT_MIR const_promotion_extern_static.BAR-{promoted#0}.SimplifyCfg-pre-optimizations.after.mir static mut BAR: *const &i32 = [&Y].as_ptr(); // EMIT_MIR const_promotion_extern_static.FOO.PromoteTemps.diff -// EMIT_MIR const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-pre-optimizations.after.mir +// EMIT_MIR const_promotion_extern_static.FOO-{promoted#0}.SimplifyCfg-pre-optimizations.after.mir static mut FOO: *const &i32 = [unsafe { &X }].as_ptr(); // EMIT_MIR const_promotion_extern_static.BOP.built.after.mir diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff index b7cb37a335fa8..0ff74319ea945 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff @@ -23,7 +23,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - _9 = const main::promoted[0]; + _9 = const main::{promoted#0}; _3 = &(*_9); _2 = &raw const (*_3); _1 = move _2 as *const [i32] (PointerCoercion(Unsize, Implicit)); diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff index 50388cbac361f..84312cc2cfbc8 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff @@ -23,7 +23,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - _9 = const main::promoted[0]; + _9 = const main::{promoted#0}; _3 = &(*_9); _2 = &raw const (*_3); _1 = move _2 as *const [i32] (PointerCoercion(Unsize, Implicit)); diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff index b7cb37a335fa8..0ff74319ea945 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff @@ -23,7 +23,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - _9 = const main::promoted[0]; + _9 = const main::{promoted#0}; _3 = &(*_9); _2 = &raw const (*_3); _1 = move _2 as *const [i32] (PointerCoercion(Unsize, Implicit)); diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff index 50388cbac361f..84312cc2cfbc8 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff @@ -23,7 +23,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - _9 = const main::promoted[0]; + _9 = const main::{promoted#0}; _3 = &(*_9); _2 = &raw const (*_3); _1 = move _2 as *const [i32] (PointerCoercion(Unsize, Implicit)); diff --git a/tests/mir-opt/const_prop/ref_deref.main.GVN.diff b/tests/mir-opt/const_prop/ref_deref.main.GVN.diff index b9e269266b0b1..8150dd546c786 100644 --- a/tests/mir-opt/const_prop/ref_deref.main.GVN.diff +++ b/tests/mir-opt/const_prop/ref_deref.main.GVN.diff @@ -14,7 +14,7 @@ bb0: { StorageLive(_1); StorageLive(_2); - _4 = const main::promoted[0]; + _4 = const main::{promoted#0}; _2 = &(*_4); - _1 = copy (*_2); + _1 = const 4_i32; diff --git a/tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff b/tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff index dcc13c9251c41..3768d43d8b1df 100644 --- a/tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff +++ b/tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff @@ -14,7 +14,7 @@ bb0: { StorageLive(_1); StorageLive(_2); - _4 = const main::promoted[0]; + _4 = const main::{promoted#0}; _2 = &((*_4).1: i32); - _1 = copy (*_2); + _1 = const 5_i32; diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff index d6e81debccd81..ce632b3dd2693 100644 --- a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff @@ -21,7 +21,7 @@ StorageLive(_2); StorageLive(_3); StorageLive(_4); - _9 = const main::promoted[0]; + _9 = const main::{promoted#0}; _4 = copy _9; - _3 = copy _4; - _2 = move _3 as &[u32] (PointerCoercion(Unsize, AsCast)); diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff index 6713e531892ae..b361044ea4d02 100644 --- a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff @@ -21,7 +21,7 @@ StorageLive(_2); StorageLive(_3); StorageLive(_4); - _9 = const main::promoted[0]; + _9 = const main::{promoted#0}; _4 = copy _9; - _3 = copy _4; - _2 = move _3 as &[u32] (PointerCoercion(Unsize, AsCast)); diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff index d6e81debccd81..ce632b3dd2693 100644 --- a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff @@ -21,7 +21,7 @@ StorageLive(_2); StorageLive(_3); StorageLive(_4); - _9 = const main::promoted[0]; + _9 = const main::{promoted#0}; _4 = copy _9; - _3 = copy _4; - _2 = move _3 as &[u32] (PointerCoercion(Unsize, AsCast)); diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff index 6713e531892ae..b361044ea4d02 100644 --- a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff @@ -21,7 +21,7 @@ StorageLive(_2); StorageLive(_3); StorageLive(_4); - _9 = const main::promoted[0]; + _9 = const main::{promoted#0}; _4 = copy _9; - _3 = copy _4; - _2 = move _3 as &[u32] (PointerCoercion(Unsize, AsCast)); diff --git a/tests/mir-opt/copy-prop/borrowed_local.borrow_in_loop.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/borrowed_local.borrow_in_loop.CopyProp.panic-abort.diff index 3d76cd65e0385..7b2dc6160b645 100644 --- a/tests/mir-opt/copy-prop/borrowed_local.borrow_in_loop.CopyProp.panic-abort.diff +++ b/tests/mir-opt/copy-prop/borrowed_local.borrow_in_loop.CopyProp.panic-abort.diff @@ -36,7 +36,7 @@ bb0: { StorageLive(_1); StorageLive(_2); - _17 = const borrow_in_loop::promoted[0]; + _17 = const borrow_in_loop::{promoted#0}; _2 = &(*_17); - StorageLive(_4); goto -> bb1; diff --git a/tests/mir-opt/copy-prop/borrowed_local.borrow_in_loop.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/borrowed_local.borrow_in_loop.CopyProp.panic-unwind.diff index 3d76cd65e0385..7b2dc6160b645 100644 --- a/tests/mir-opt/copy-prop/borrowed_local.borrow_in_loop.CopyProp.panic-unwind.diff +++ b/tests/mir-opt/copy-prop/borrowed_local.borrow_in_loop.CopyProp.panic-unwind.diff @@ -36,7 +36,7 @@ bb0: { StorageLive(_1); StorageLive(_2); - _17 = const borrow_in_loop::promoted[0]; + _17 = const borrow_in_loop::{promoted#0}; _2 = &(*_17); - StorageLive(_4); goto -> bb1; diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff index fd9ef54fe775f..9cfd65489db8a 100644 --- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff @@ -29,7 +29,7 @@ StorageLive(_2); StorageLive(_3); StorageLive(_4); - _14 = const main::promoted[0]; + _14 = const main::{promoted#0}; _4 = copy _14; _3 = copy _4; _2 = move _3 as &[u32] (PointerCoercion(Unsize, AsCast)); diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff index 1fec08c256201..29ea66c07380d 100644 --- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff @@ -29,7 +29,7 @@ StorageLive(_2); StorageLive(_3); StorageLive(_4); - _14 = const main::promoted[0]; + _14 = const main::{promoted#0}; _4 = copy _14; _3 = copy _4; _2 = move _3 as &[u32] (PointerCoercion(Unsize, AsCast)); diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff index fd9ef54fe775f..9cfd65489db8a 100644 --- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff @@ -29,7 +29,7 @@ StorageLive(_2); StorageLive(_3); StorageLive(_4); - _14 = const main::promoted[0]; + _14 = const main::{promoted#0}; _4 = copy _14; _3 = copy _4; _2 = move _3 as &[u32] (PointerCoercion(Unsize, AsCast)); diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff index 1fec08c256201..29ea66c07380d 100644 --- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff @@ -29,7 +29,7 @@ StorageLive(_2); StorageLive(_3); StorageLive(_4); - _14 = const main::promoted[0]; + _14 = const main::{promoted#0}; _4 = copy _14; _3 = copy _4; _2 = move _3 as &[u32] (PointerCoercion(Unsize, AsCast)); diff --git a/tests/mir-opt/debuginfo/ref_prop.remap_debuginfo_locals.ReferencePropagation.diff b/tests/mir-opt/debuginfo/ref_prop.remap_debuginfo_locals.ReferencePropagation.diff index 2d93b1d842fa1..8fe0ee77265b9 100644 --- a/tests/mir-opt/debuginfo/ref_prop.remap_debuginfo_locals.ReferencePropagation.diff +++ b/tests/mir-opt/debuginfo/ref_prop.remap_debuginfo_locals.ReferencePropagation.diff @@ -17,7 +17,7 @@ - StorageLive(_1); - StorageLive(_2); - StorageLive(_3); - _5 = const remap_debuginfo_locals::promoted[0]; + _5 = const remap_debuginfo_locals::{promoted#0}; - _3 = &(*_5); - _2 = &raw const (*_3); - // DBG: _1 = &(*_2); diff --git a/tests/mir-opt/debuginfo/single_use_consts.invalid_debuginfo.SingleUseConsts.diff b/tests/mir-opt/debuginfo/single_use_consts.invalid_debuginfo.SingleUseConsts.diff index 09e9f26546a85..8a4e9eba1937d 100644 --- a/tests/mir-opt/debuginfo/single_use_consts.invalid_debuginfo.SingleUseConsts.diff +++ b/tests/mir-opt/debuginfo/single_use_consts.invalid_debuginfo.SingleUseConsts.diff @@ -12,7 +12,7 @@ let mut _6: &isize; scope 2 (inlined bar) { - debug x => _4; -+ debug x => const foo::promoted[0]; ++ debug x => const foo::{promoted#0}; let _7: isize; let mut _9: &isize; let _10: &isize; @@ -22,7 +22,7 @@ let mut _8: &isize; scope 4 { - debug z => _4; -+ debug z => const foo::promoted[0]; ++ debug z => const foo::{promoted#0}; } } } @@ -31,7 +31,7 @@ bb0: { StorageLive(_1); StorageLive(_4); -- _4 = const foo::promoted[0]; +- _4 = const foo::{promoted#0}; + nop; StorageLive(_7); - _7 = const 1_isize; diff --git a/tests/mir-opt/derefer_complex_case.main.Derefer.panic-abort.diff b/tests/mir-opt/derefer_complex_case.main.Derefer.panic-abort.diff index bac62c886688d..a70f2f32b84d0 100644 --- a/tests/mir-opt/derefer_complex_case.main.Derefer.panic-abort.diff +++ b/tests/mir-opt/derefer_complex_case.main.Derefer.panic-abort.diff @@ -28,7 +28,7 @@ bb0: { StorageLive(_1); StorageLive(_2); - _14 = const main::promoted[0]; + _14 = const main::{promoted#0}; _2 = &(*_14); _1 = <&[i32; 2] as IntoIterator>::into_iter(move _2) -> [return: bb1, unwind: bb8]; } diff --git a/tests/mir-opt/derefer_complex_case.main.Derefer.panic-unwind.diff b/tests/mir-opt/derefer_complex_case.main.Derefer.panic-unwind.diff index 55cd2e427eea9..ceb9b9ef44e17 100644 --- a/tests/mir-opt/derefer_complex_case.main.Derefer.panic-unwind.diff +++ b/tests/mir-opt/derefer_complex_case.main.Derefer.panic-unwind.diff @@ -28,7 +28,7 @@ bb0: { StorageLive(_1); StorageLive(_2); - _14 = const main::promoted[0]; + _14 = const main::{promoted#0}; _2 = &(*_14); _1 = <&[i32; 2] as IntoIterator>::into_iter(move _2) -> [return: bb1, unwind continue]; } diff --git a/tests/mir-opt/gvn.wide_ptr_provenance.GVN.panic-abort.diff b/tests/mir-opt/gvn.wide_ptr_provenance.GVN.panic-abort.diff index 43cd8ba7809a2..229d56fbd5c0d 100644 --- a/tests/mir-opt/gvn.wide_ptr_provenance.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.wide_ptr_provenance.GVN.panic-abort.diff @@ -61,7 +61,7 @@ StorageLive(_3); StorageLive(_4); StorageLive(_5); - _44 = const wide_ptr_provenance::promoted[1]; + _44 = const wide_ptr_provenance::{promoted#1}; _5 = &(*_44); _4 = &(*_5); _3 = move _4 as &dyn std::marker::Send (PointerCoercion(Unsize, AsCast)); @@ -79,7 +79,7 @@ StorageLive(_9); StorageLive(_10); StorageLive(_11); - _43 = const wide_ptr_provenance::promoted[0]; + _43 = const wide_ptr_provenance::{promoted#0}; _11 = &(*_43); _10 = &(*_11); _9 = move _10 as &dyn std::marker::Send (PointerCoercion(Unsize, AsCast)); diff --git a/tests/mir-opt/gvn.wide_ptr_provenance.GVN.panic-unwind.diff b/tests/mir-opt/gvn.wide_ptr_provenance.GVN.panic-unwind.diff index 49cca20153bd4..f3d5e34c1080c 100644 --- a/tests/mir-opt/gvn.wide_ptr_provenance.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.wide_ptr_provenance.GVN.panic-unwind.diff @@ -61,7 +61,7 @@ StorageLive(_3); StorageLive(_4); StorageLive(_5); - _44 = const wide_ptr_provenance::promoted[1]; + _44 = const wide_ptr_provenance::{promoted#1}; _5 = &(*_44); _4 = &(*_5); _3 = move _4 as &dyn std::marker::Send (PointerCoercion(Unsize, AsCast)); @@ -79,7 +79,7 @@ StorageLive(_9); StorageLive(_10); StorageLive(_11); - _43 = const wide_ptr_provenance::promoted[0]; + _43 = const wide_ptr_provenance::{promoted#0}; _11 = &(*_43); _10 = &(*_11); _9 = move _10 as &dyn std::marker::Send (PointerCoercion(Unsize, AsCast)); diff --git a/tests/mir-opt/gvn.wide_ptr_same_provenance.GVN.panic-abort.diff b/tests/mir-opt/gvn.wide_ptr_same_provenance.GVN.panic-abort.diff index 0165136fda4ca..4e988b7ada1c4 100644 --- a/tests/mir-opt/gvn.wide_ptr_same_provenance.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.wide_ptr_same_provenance.GVN.panic-abort.diff @@ -62,7 +62,7 @@ bb0: { StorageLive(_1); - _47 = const wide_ptr_same_provenance::promoted[0]; + _47 = const wide_ptr_same_provenance::{promoted#0}; _1 = &(*_47); StorageLive(_3); - StorageLive(_4); diff --git a/tests/mir-opt/gvn.wide_ptr_same_provenance.GVN.panic-unwind.diff b/tests/mir-opt/gvn.wide_ptr_same_provenance.GVN.panic-unwind.diff index bbaab46b47560..e3db82e058c0f 100644 --- a/tests/mir-opt/gvn.wide_ptr_same_provenance.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.wide_ptr_same_provenance.GVN.panic-unwind.diff @@ -62,7 +62,7 @@ bb0: { StorageLive(_1); - _47 = const wide_ptr_same_provenance::promoted[0]; + _47 = const wide_ptr_same_provenance::{promoted#0}; _1 = &(*_47); StorageLive(_3); - StorageLive(_4); diff --git a/tests/mir-opt/gvn_uninhabited.f.GVN.panic-abort.diff b/tests/mir-opt/gvn_uninhabited.f.GVN.panic-abort.diff index a3e4796d088e4..dfe0b916edd57 100644 --- a/tests/mir-opt/gvn_uninhabited.f.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn_uninhabited.f.GVN.panic-abort.diff @@ -15,7 +15,7 @@ bb0: { StorageLive(_2); StorageLive(_3); - _5 = const f::promoted[0]; + _5 = const f::{promoted#0}; _3 = &(*_5); - _2 = copy ((*_3).1: E); + _2 = const Scalar(0x00000000): E; diff --git a/tests/mir-opt/gvn_uninhabited.f.GVN.panic-unwind.diff b/tests/mir-opt/gvn_uninhabited.f.GVN.panic-unwind.diff index a3e4796d088e4..dfe0b916edd57 100644 --- a/tests/mir-opt/gvn_uninhabited.f.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn_uninhabited.f.GVN.panic-unwind.diff @@ -15,7 +15,7 @@ bb0: { StorageLive(_2); StorageLive(_3); - _5 = const f::promoted[0]; + _5 = const f::{promoted#0}; _3 = &(*_5); - _2 = copy ((*_3).1: E); + _2 = const Scalar(0x00000000): E; diff --git a/tests/mir-opt/inline/inline_retag.bar.Inline.after.mir b/tests/mir-opt/inline/inline_retag.bar.Inline.after.mir index 9a256ea19496a..8d625e2f0b451 100644 --- a/tests/mir-opt/inline/inline_retag.bar.Inline.after.mir +++ b/tests/mir-opt/inline/inline_retag.bar.Inline.after.mir @@ -29,13 +29,13 @@ fn bar() -> bool { _2 = copy _1; StorageLive(_3); StorageLive(_4); - _10 = const bar::promoted[1]; + _10 = const bar::{promoted#1}; Retag(_10); _4 = copy _10; _3 = copy _4; StorageLive(_6); StorageLive(_7); - _9 = const bar::promoted[0]; + _9 = const bar::{promoted#0}; Retag(_9); _7 = copy _9; _6 = copy _7; diff --git a/tests/mir-opt/inline/issue_106141.outer.Inline.panic-abort.diff b/tests/mir-opt/inline/issue_106141.outer.Inline.panic-abort.diff index e87a565f0fc98..e395970c6ee72 100644 --- a/tests/mir-opt/inline/issue_106141.outer.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/issue_106141.outer.Inline.panic-abort.diff @@ -19,7 +19,7 @@ - _0 = inner() -> [return: bb1, unwind unreachable]; + StorageLive(_1); + StorageLive(_2); -+ _1 = const inner::promoted[0]; ++ _1 = const inner::{promoted#0}; + _0 = index() -> [return: bb1, unwind unreachable]; } diff --git a/tests/mir-opt/inline/issue_106141.outer.Inline.panic-unwind.diff b/tests/mir-opt/inline/issue_106141.outer.Inline.panic-unwind.diff index 834851b75adf1..bb57037de712f 100644 --- a/tests/mir-opt/inline/issue_106141.outer.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/issue_106141.outer.Inline.panic-unwind.diff @@ -19,7 +19,7 @@ - _0 = inner() -> [return: bb1, unwind continue]; + StorageLive(_1); + StorageLive(_2); -+ _1 = const inner::promoted[0]; ++ _1 = const inner::{promoted#0}; + _0 = index() -> [return: bb1, unwind continue]; } diff --git a/tests/mir-opt/inline_default_trait_body.Trait-a.Inline.panic-abort.diff b/tests/mir-opt/inline_default_trait_body.Trait-a.Inline.panic-abort.diff index db72e84f24ba8..75ad4c8fe33c1 100644 --- a/tests/mir-opt/inline_default_trait_body.Trait-a.Inline.panic-abort.diff +++ b/tests/mir-opt/inline_default_trait_body.Trait-a.Inline.panic-abort.diff @@ -12,7 +12,7 @@ bb0: { StorageLive(_2); StorageLive(_3); - _5 = const ::a::promoted[0]; + _5 = const ::a::{promoted#0}; _3 = &(*_5); _2 = <() as Trait>::b(move _3) -> [return: bb1, unwind unreachable]; } diff --git a/tests/mir-opt/inline_default_trait_body.Trait-a.Inline.panic-unwind.diff b/tests/mir-opt/inline_default_trait_body.Trait-a.Inline.panic-unwind.diff index aad5a62f82d48..cc4e85b15bf64 100644 --- a/tests/mir-opt/inline_default_trait_body.Trait-a.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline_default_trait_body.Trait-a.Inline.panic-unwind.diff @@ -12,7 +12,7 @@ bb0: { StorageLive(_2); StorageLive(_3); - _5 = const ::a::promoted[0]; + _5 = const ::a::{promoted#0}; _3 = &(*_5); _2 = <() as Trait>::b(move _3) -> [return: bb1, unwind continue]; } diff --git a/tests/mir-opt/inline_default_trait_body.Trait-b.Inline.panic-abort.diff b/tests/mir-opt/inline_default_trait_body.Trait-b.Inline.panic-abort.diff index b5ca892077e14..f899cc10f2f5b 100644 --- a/tests/mir-opt/inline_default_trait_body.Trait-b.Inline.panic-abort.diff +++ b/tests/mir-opt/inline_default_trait_body.Trait-b.Inline.panic-abort.diff @@ -12,7 +12,7 @@ bb0: { StorageLive(_2); StorageLive(_3); - _5 = const ::b::promoted[0]; + _5 = const ::b::{promoted#0}; _3 = &(*_5); _2 = <() as Trait>::a(move _3) -> [return: bb1, unwind unreachable]; } diff --git a/tests/mir-opt/inline_default_trait_body.Trait-b.Inline.panic-unwind.diff b/tests/mir-opt/inline_default_trait_body.Trait-b.Inline.panic-unwind.diff index 1f51d2e4b5e5e..2cf1d4dc1e10f 100644 --- a/tests/mir-opt/inline_default_trait_body.Trait-b.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline_default_trait_body.Trait-b.Inline.panic-unwind.diff @@ -12,7 +12,7 @@ bb0: { StorageLive(_2); StorageLive(_3); - _5 = const ::b::promoted[0]; + _5 = const ::b::{promoted#0}; _3 = &(*_5); _2 = <() as Trait>::a(move _3) -> [return: bb1, unwind continue]; } diff --git a/tests/mir-opt/jump_threading.chained_conditions.JumpThreading.panic-abort.diff b/tests/mir-opt/jump_threading.chained_conditions.JumpThreading.panic-abort.diff index a59d76b05a99f..21b6ad78bebd9 100644 --- a/tests/mir-opt/jump_threading.chained_conditions.JumpThreading.panic-abort.diff +++ b/tests/mir-opt/jump_threading.chained_conditions.JumpThreading.panic-abort.diff @@ -227,7 +227,7 @@ _9 = &(*_6); _8 = &_9; StorageLive(_10); - _21 = const chained_conditions::promoted[1]; + _21 = const chained_conditions::{promoted#1}; _10 = &(*_21); StorageLive(_27); StorageLive(_28); @@ -289,7 +289,7 @@ _16 = &(*_13); _15 = &_16; StorageLive(_17); - _20 = const chained_conditions::promoted[0]; + _20 = const chained_conditions::{promoted#0}; _17 = &(*_20); StorageLive(_47); StorageLive(_48); diff --git a/tests/mir-opt/jump_threading.chained_conditions.JumpThreading.panic-unwind.diff b/tests/mir-opt/jump_threading.chained_conditions.JumpThreading.panic-unwind.diff index b0811ab7f0685..59ac1a648dc8c 100644 --- a/tests/mir-opt/jump_threading.chained_conditions.JumpThreading.panic-unwind.diff +++ b/tests/mir-opt/jump_threading.chained_conditions.JumpThreading.panic-unwind.diff @@ -227,7 +227,7 @@ _9 = &(*_6); _8 = &_9; StorageLive(_10); - _21 = const chained_conditions::promoted[1]; + _21 = const chained_conditions::{promoted#1}; _10 = &(*_21); StorageLive(_27); StorageLive(_28); @@ -289,7 +289,7 @@ _16 = &(*_13); _15 = &_16; StorageLive(_17); - _20 = const chained_conditions::promoted[0]; + _20 = const chained_conditions::{promoted#0}; _17 = &(*_20); StorageLive(_47); StorageLive(_48); diff --git a/tests/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.panic-abort.diff b/tests/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.panic-abort.diff index 564f07ff26d4f..8ad5b127bb707 100644 --- a/tests/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.panic-abort.diff +++ b/tests/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.panic-abort.diff @@ -41,7 +41,7 @@ StorageLive(_5); StorageLive(_6); StorageLive(_7); - _19 = const discriminant::::promoted[2]; + _19 = const discriminant::{promoted#2}; _7 = &(*_19); _6 = &(*_7); - _5 = discriminant_value::(move _6) -> [return: bb2, unwind unreachable]; @@ -56,7 +56,7 @@ StorageLive(_9); StorageLive(_10); StorageLive(_11); - _18 = const discriminant::::promoted[1]; + _18 = const discriminant::{promoted#1}; _11 = &(*_18); _10 = &(*_11); - _9 = discriminant_value::<()>(move _10) -> [return: bb3, unwind unreachable]; @@ -71,7 +71,7 @@ StorageLive(_13); StorageLive(_14); StorageLive(_15); - _17 = const discriminant::::promoted[0]; + _17 = const discriminant::{promoted#0}; _15 = &(*_17); _14 = &(*_15); - _13 = discriminant_value::(move _14) -> [return: bb4, unwind unreachable]; diff --git a/tests/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.panic-unwind.diff b/tests/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.panic-unwind.diff index 7410af284dcd0..4bf28e6b5a94f 100644 --- a/tests/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.panic-unwind.diff +++ b/tests/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.panic-unwind.diff @@ -41,7 +41,7 @@ StorageLive(_5); StorageLive(_6); StorageLive(_7); - _19 = const discriminant::::promoted[2]; + _19 = const discriminant::{promoted#2}; _7 = &(*_19); _6 = &(*_7); - _5 = discriminant_value::(move _6) -> [return: bb2, unwind unreachable]; @@ -56,7 +56,7 @@ StorageLive(_9); StorageLive(_10); StorageLive(_11); - _18 = const discriminant::::promoted[1]; + _18 = const discriminant::{promoted#1}; _11 = &(*_18); _10 = &(*_11); - _9 = discriminant_value::<()>(move _10) -> [return: bb3, unwind unreachable]; @@ -71,7 +71,7 @@ StorageLive(_13); StorageLive(_14); StorageLive(_15); - _17 = const discriminant::::promoted[0]; + _17 = const discriminant::{promoted#0}; _15 = &(*_17); _14 = &(*_15); - _13 = discriminant_value::(move _14) -> [return: bb4, unwind unreachable]; diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir index 6d3519846023a..575659e6d0ded 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir @@ -180,23 +180,20 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { bb4: { StorageLive(_32); - StorageLive(_29); StorageLive(_30); StorageLive(_27); - StorageLive(_13); - StorageLive(_14); - StorageLive(_20); StorageLive(_24); - StorageLive(_15); - StorageLive(_26); StorageLive(_16); + StorageLive(_13); _13 = copy _8; + StorageLive(_14); _14 = copy _11; switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb8]; } bb5: { StorageLive(_18); + StorageLive(_15); _15 = copy _14 as std::ptr::NonNull (Transmute); _16 = copy _13 as *mut T (Transmute); StorageLive(_17); @@ -207,6 +204,7 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb6: { + StorageDead(_15); StorageDead(_18); StorageLive(_19); _19 = Offset(copy _16, const 1_usize); @@ -216,27 +214,27 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb7: { + StorageDead(_15); StorageDead(_18); goto -> bb10; } bb8: { + StorageLive(_20); _20 = copy _14 as usize (Transmute); switchInt(copy _20) -> [0: bb9, otherwise: bb12]; } bb9: { + StorageDead(_20); goto -> bb10; } bb10: { - StorageDead(_16); - StorageDead(_26); - StorageDead(_15); - StorageDead(_24); - StorageDead(_20); StorageDead(_14); StorageDead(_13); + StorageDead(_16); + StorageDead(_24); StorageDead(_27); StorageLive(_21); StorageLive(_23); @@ -246,7 +244,6 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { StorageDead(_23); StorageDead(_21); StorageDead(_30); - StorageDead(_29); StorageDead(_32); StorageDead(_12); drop(_2) -> [return: bb11, unwind unreachable]; @@ -259,24 +256,25 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { bb12: { _24 = SubUnchecked(copy _20, const 1_usize); _11 = copy _24 as *const T (Transmute); + StorageDead(_20); goto -> bb13; } bb13: { + StorageLive(_26); StorageLive(_25); _25 = copy _13 as *const T (Transmute); _26 = &(*_25); StorageDead(_25); _27 = Option::<&T>::Some(copy _26); - StorageDead(_16); StorageDead(_26); - StorageDead(_15); - StorageDead(_24); - StorageDead(_20); StorageDead(_14); StorageDead(_13); + StorageDead(_16); + StorageDead(_24); _28 = copy ((_27 as Some).0: &T); StorageDead(_27); + StorageLive(_29); _29 = copy _12; _30 = AddWithOverflow(copy _12, const 1_usize); assert(!move (_30.1: bool), "attempt to compute `{} + {}`, which would overflow", copy _12, const 1_usize) -> [success: bb14, unwind unreachable]; @@ -288,9 +286,11 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { _31 = (copy _29, copy _28); _32 = Option::<(usize, &T)>::Some(move _31); StorageDead(_31); - StorageDead(_30); StorageDead(_29); + StorageDead(_30); + StorageLive(_33); _33 = copy (((_32 as Some).0: (usize, &T)).0: usize); + StorageLive(_34); _34 = copy (((_32 as Some).0: (usize, &T)).1: &T); StorageLive(_35); _35 = &_2; @@ -302,6 +302,8 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { bb15: { StorageDead(_36); StorageDead(_35); + StorageDead(_34); + StorageDead(_33); StorageDead(_32); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir index 6e27d02641687..f41dbd567003e 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir @@ -142,20 +142,18 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb4: { StorageLive(_23); - StorageLive(_12); - StorageLive(_13); - StorageLive(_19); StorageLive(_20); - StorageLive(_14); - StorageLive(_22); StorageLive(_15); + StorageLive(_12); _12 = copy _8; + StorageLive(_13); _13 = copy _11; switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb8]; } bb5: { StorageLive(_17); + StorageLive(_14); _14 = copy _13 as std::ptr::NonNull (Transmute); _15 = copy _12 as *mut T (Transmute); StorageLive(_16); @@ -166,6 +164,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb6: { + StorageDead(_14); StorageDead(_17); StorageLive(_18); _18 = Offset(copy _15, const 1_usize); @@ -175,27 +174,27 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb7: { + StorageDead(_14); StorageDead(_17); goto -> bb10; } bb8: { + StorageLive(_19); _19 = copy _13 as usize (Transmute); switchInt(copy _19) -> [0: bb9, otherwise: bb12]; } bb9: { + StorageDead(_19); goto -> bb10; } bb10: { - StorageDead(_15); - StorageDead(_22); - StorageDead(_14); - StorageDead(_20); - StorageDead(_19); StorageDead(_13); StorageDead(_12); + StorageDead(_15); + StorageDead(_20); StorageDead(_23); drop(_2) -> [return: bb11, unwind unreachable]; } @@ -207,22 +206,23 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb12: { _20 = SubUnchecked(copy _19, const 1_usize); _11 = copy _20 as *const T (Transmute); + StorageDead(_19); goto -> bb13; } bb13: { + StorageLive(_22); StorageLive(_21); _21 = copy _12 as *const T (Transmute); _22 = &(*_21); StorageDead(_21); _23 = Option::<&T>::Some(copy _22); - StorageDead(_15); StorageDead(_22); - StorageDead(_14); - StorageDead(_20); - StorageDead(_19); StorageDead(_13); StorageDead(_12); + StorageDead(_15); + StorageDead(_20); + StorageLive(_24); _24 = copy ((_23 as Some).0: &T); StorageLive(_25); _25 = &_2; @@ -234,6 +234,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb14: { StorageDead(_26); StorageDead(_25); + StorageDead(_24); StorageDead(_23); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir index 145375990710b..43e2d24674d96 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir @@ -72,11 +72,15 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb4: { + StorageLive(_7); _7 = copy _4; _4 = AddUnchecked(copy _7, const 1_usize); _8 = Option::::Some(copy _7); + StorageDead(_7); StorageDead(_6); + StorageLive(_9); _9 = copy ((_8 as Some).0: usize); + StorageLive(_11); _10 = Lt(copy _9, copy _3); assert(move _10, "index out of bounds: the length is {} but the index is {}", copy _3, copy _9) -> [success: bb5, unwind unreachable]; } @@ -93,6 +97,8 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { bb6: { StorageDead(_13); StorageDead(_12); + StorageDead(_11); + StorageDead(_9); StorageDead(_8); goto -> bb1; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir index ac2b0f23b9f90..1f96a8e14a5b2 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir @@ -132,10 +132,10 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb0: { StorageLive(_12); - StorageLive(_3); - StorageLive(_8); StorageLive(_11); + StorageLive(_3); _3 = PtrMetadata(copy _1); + StorageLive(_8); StorageLive(_5); StorageLive(_4); _4 = &raw const (*_1); @@ -170,9 +170,9 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb3: { _12 = std::slice::Iter::<'_, T> { ptr: copy _8, end_or_len: copy _11, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_11); StorageDead(_8); StorageDead(_3); + StorageDead(_11); _13 = Rev::> { iter: copy _12 }; StorageDead(_12); StorageLive(_14); @@ -182,15 +182,12 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb4: { StorageLive(_35); - StorageLive(_22); - StorageLive(_21); - StorageLive(_16); - StorageLive(_34); StorageLive(_20); switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb6]; } bb5: { + StorageLive(_16); StorageLive(_15); _15 = copy ((_14.0: std::slice::Iter<'_, T>).1: *const T); _16 = copy _15 as std::ptr::NonNull (Transmute); @@ -205,13 +202,18 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { _20 = Eq(copy _18, copy _19); StorageDead(_19); StorageDead(_18); + StorageDead(_16); goto -> bb7; } bb6: { + StorageLive(_22); + StorageLive(_21); _21 = copy ((_14.0: std::slice::Iter<'_, T>).1: *const T); _22 = copy _21 as usize (Transmute); + StorageDead(_21); _20 = Eq(copy _22, const 0_usize); + StorageDead(_22); goto -> bb7; } @@ -220,6 +222,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb8: { + StorageLive(_34); StorageLive(_28); StorageLive(_30); StorageLive(_24); @@ -279,11 +282,9 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { StorageDead(_33); StorageDead(_28); _35 = Option::<&T>::Some(copy _34); - StorageDead(_20); StorageDead(_34); - StorageDead(_16); - StorageDead(_21); - StorageDead(_22); + StorageDead(_20); + StorageLive(_36); _36 = copy ((_35 as Some).0: &T); StorageLive(_37); _37 = &_2; @@ -295,16 +296,13 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb14: { StorageDead(_38); StorageDead(_37); + StorageDead(_36); StorageDead(_35); goto -> bb4; } bb15: { StorageDead(_20); - StorageDead(_34); - StorageDead(_16); - StorageDead(_21); - StorageDead(_22); StorageDead(_35); StorageDead(_14); drop(_2) -> [return: bb16, unwind unreachable]; diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_generic_is_empty.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_generic_is_empty.PreCodegen.after.panic-abort.mir index 9b510380b10b2..04f78fa3e7e3b 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_generic_is_empty.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_generic_is_empty.PreCodegen.after.panic-abort.mir @@ -30,13 +30,11 @@ fn slice_iter_generic_is_empty(_1: &std::slice::Iter<'_, T>) -> bool { } bb0: { - StorageLive(_8); - StorageLive(_7); - StorageLive(_3); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageLive(_3); StorageLive(_2); _2 = copy ((*_1).1: *const T); _3 = copy _2 as std::ptr::NonNull (Transmute); @@ -51,20 +49,22 @@ fn slice_iter_generic_is_empty(_1: &std::slice::Iter<'_, T>) -> bool { _0 = Eq(copy _5, copy _6); StorageDead(_6); StorageDead(_5); + StorageDead(_3); goto -> bb3; } bb2: { + StorageLive(_8); + StorageLive(_7); _7 = copy ((*_1).1: *const T); _8 = copy _7 as usize (Transmute); + StorageDead(_7); _0 = Eq(copy _8, const 0_usize); + StorageDead(_8); goto -> bb3; } bb3: { - StorageDead(_3); - StorageDead(_7); - StorageDead(_8); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir index 99f793ea67249..94471cbb157c5 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir @@ -73,16 +73,13 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut } bb0: { - StorageLive(_9); - StorageLive(_8); - StorageLive(_3); StorageLive(_2); - StorageLive(_21); StorageLive(_7); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageLive(_3); _2 = copy ((*_1).1: *mut T); _3 = copy _2 as std::ptr::NonNull (Transmute); StorageLive(_5); @@ -95,13 +92,18 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut _7 = Eq(copy _5, copy _6); StorageDead(_6); StorageDead(_5); + StorageDead(_3); goto -> bb3; } bb2: { + StorageLive(_9); + StorageLive(_8); _8 = copy ((*_1).1: *mut T); _9 = copy _8 as usize (Transmute); + StorageDead(_8); _7 = Eq(copy _9, const 0_usize); + StorageDead(_9); goto -> bb3; } @@ -110,6 +112,7 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut } bb4: { + StorageLive(_21); StorageLive(_15); StorageLive(_17); StorageLive(_11); @@ -169,6 +172,7 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut StorageDead(_20); StorageDead(_15); _0 = Option::<&mut T>::Some(copy _21); + StorageDead(_21); goto -> bb11; } @@ -179,11 +183,7 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut bb11: { StorageDead(_7); - StorageDead(_21); StorageDead(_2); - StorageDead(_3); - StorageDead(_8); - StorageDead(_9); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir index 5711b556203ac..70e21435cc18f 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir @@ -53,20 +53,18 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { } bb0: { - StorageLive(_2); - StorageLive(_3); - StorageLive(_10); StorageLive(_11); - StorageLive(_4); - StorageLive(_13); StorageLive(_5); + StorageLive(_2); _2 = copy ((*_1).0: std::ptr::NonNull); + StorageLive(_3); _3 = copy ((*_1).1: *const T); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb4]; } bb1: { StorageLive(_7); + StorageLive(_4); _4 = copy _3 as std::ptr::NonNull (Transmute); _5 = copy _2 as *mut T (Transmute); StorageLive(_6); @@ -77,6 +75,7 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { } bb2: { + StorageDead(_4); StorageDead(_7); StorageLive(_9); StorageLive(_8); @@ -85,48 +84,57 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { StorageDead(_8); ((*_1).0: std::ptr::NonNull) = move _9; StorageDead(_9); - goto -> bb7; + goto -> bb8; } bb3: { + StorageDead(_4); _0 = const {transmute(0x0000000000000000): Option<&T>}; StorageDead(_7); - goto -> bb8; + goto -> bb6; } bb4: { + StorageLive(_10); _10 = copy _3 as usize (Transmute); - switchInt(copy _10) -> [0: bb5, otherwise: bb6]; + switchInt(copy _10) -> [0: bb5, otherwise: bb7]; } bb5: { _0 = const {transmute(0x0000000000000000): Option<&T>}; - goto -> bb8; + StorageDead(_10); + goto -> bb6; } bb6: { + StorageDead(_3); + StorageDead(_2); + goto -> bb9; + } + + bb7: { _11 = SubUnchecked(copy _10, const 1_usize); ((*_1).1: *const T) = copy _11 as *const T (Transmute); - goto -> bb7; + StorageDead(_10); + goto -> bb8; } - bb7: { + bb8: { + StorageLive(_13); StorageLive(_12); _12 = copy _2 as *const T (Transmute); _13 = &(*_12); StorageDead(_12); _0 = Option::<&T>::Some(copy _13); - goto -> bb8; + StorageDead(_13); + StorageDead(_3); + StorageDead(_2); + goto -> bb9; } - bb8: { + bb9: { StorageDead(_5); - StorageDead(_13); - StorageDead(_4); StorageDead(_11); - StorageDead(_10); - StorageDead(_3); - StorageDead(_2); return; } } diff --git a/tests/mir-opt/reference_prop.debuginfo.ReferencePropagation.diff b/tests/mir-opt/reference_prop.debuginfo.ReferencePropagation.diff index 375b6096d88d8..235327ff377b4 100644 --- a/tests/mir-opt/reference_prop.debuginfo.ReferencePropagation.diff +++ b/tests/mir-opt/reference_prop.debuginfo.ReferencePropagation.diff @@ -60,7 +60,7 @@ _2 = const 5_u8; _1 = &mut _2; StorageLive(_3); - _29 = const debuginfo::promoted[2]; + _29 = const debuginfo::{promoted#2}; _3 = &((*_29).0: u8); - StorageLive(_5); - _5 = &(*_1); @@ -77,7 +77,7 @@ bb2: { StorageLive(_9); - _28 = const debuginfo::promoted[1]; + _28 = const debuginfo::{promoted#1}; _9 = &(((*_28) as Some).0: i32); - _6 = const (); StorageDead(_9); @@ -96,7 +96,7 @@ StorageLive(_11); - StorageLive(_12); StorageLive(_13); - _27 = const debuginfo::promoted[0]; + _27 = const debuginfo::{promoted#0}; _13 = &(*_27); StorageLive(_15); _15 = RangeFull; diff --git a/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-abort.mir b/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 910983ee79d35..dbad677fad49f 100644 --- a/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-abort.mir +++ b/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -105,7 +105,7 @@ fn array_casts() -> () { _15 = copy (*_16); _14 = &_15; StorageLive(_18); - _34 = const array_casts::promoted[0]; + _34 = const array_casts::{promoted#0}; Retag(_34); _18 = &(*_34); _13 = (move _14, move _18); diff --git a/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-unwind.mir b/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 8cc6bce0e6bd4..9529337894408 100644 --- a/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-unwind.mir +++ b/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -105,7 +105,7 @@ fn array_casts() -> () { _15 = copy (*_16); _14 = &_15; StorageLive(_18); - _34 = const array_casts::promoted[0]; + _34 = const array_casts::{promoted#0}; Retag(_34); _18 = &(*_34); _13 = (move _14, move _18); diff --git a/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-abort.mir b/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-abort.mir index cca2b3ae188c3..5d83795327b46 100644 --- a/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-abort.mir +++ b/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -129,7 +129,7 @@ fn main() -> () { _20 = &_21; StorageLive(_22); StorageLive(_23); - _28 = const main::promoted[0]; + _28 = const main::{promoted#0}; Retag(_28); _23 = &(*_28); _22 = &(*_23); diff --git a/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-unwind.mir b/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index bcd3a47ac04fb..f04e74158cb5e 100644 --- a/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-unwind.mir +++ b/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -129,7 +129,7 @@ fn main() -> () { _20 = &_21; StorageLive(_22); StorageLive(_23); - _28 = const main::promoted[0]; + _28 = const main::{promoted#0}; Retag(_28); _23 = &(*_28); _22 = &(*_23); From adf779fcbaf31cf25e75272c31fc26f697c5a5b0 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Sun, 26 Apr 2026 15:55:23 +0000 Subject: [PATCH 12/15] Remove `Option` from references to promoteds. --- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- .../src/check_consts/qualifs.rs | 2 +- .../src/const_eval/eval_queries.rs | 12 +++++------- .../rustc_const_eval/src/const_eval/machine.rs | 2 +- .../src/interpret/eval_context.rs | 5 ++--- compiler/rustc_hir_analysis/src/lib.rs | 2 +- compiler/rustc_middle/src/mir/consts.rs | 18 ++++-------------- compiler/rustc_middle/src/mir/interpret/mod.rs | 11 +---------- .../rustc_middle/src/mir/interpret/queries.rs | 10 +++++----- compiler/rustc_middle/src/mir/mod.rs | 9 +++------ compiler/rustc_middle/src/mir/pretty.rs | 10 +--------- .../rustc_mir_transform/src/coverage/mod.rs | 4 ---- .../rustc_mir_transform/src/promote_consts.rs | 4 ++-- compiler/rustc_public/src/ty.rs | 1 - .../src/unstable/convert/stable/mir.rs | 1 - compiler/rustc_public/src/visitor.rs | 5 ++--- src/tools/miri/src/helpers.rs | 2 +- src/tools/miri/src/machine.rs | 2 +- src/tools/miri/src/shims/foreign_items.rs | 2 +- 19 files changed, 32 insertions(+), 72 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index a1fc88fcb5b12..e8f30de78edea 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1646,7 +1646,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { let maybe_uneval = match constant.const_ { Const::Ty(_, ct) => match ct.kind() { ty::ConstKind::Unevaluated(uv) => { - Some(UnevaluatedConst { def: uv.def, args: uv.args, promoted: None }) + Some(UnevaluatedConst { def: uv.def, args: uv.args }) } _ => None, }, diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index 7df9eec29d1fa..6f55a43bab92d 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -356,7 +356,7 @@ where Const::Val(..) => None, }; - if let Some(UnevaluatedConst { def, args: _, promoted: _ }) = uneval { + if let Some(UnevaluatedConst { def, args: _ }) = uneval { let is_promoted = cx.tcx.def_kind(def) == DefKind::Promoted; // Use qualifs of the type for the promoted. Promoteds in MIR body should be possible diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index a21cb423f69a4..915dc3fae4a86 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -62,9 +62,8 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>( let (intern_kind, ret) = setup_for_eval(ecx, cid, layout)?; trace!( - "eval_body_using_ecx: pushing stack frame for global: {}{}", + "eval_body_using_ecx: pushing stack frame for global: {}", with_no_trimmed_paths!(ecx.tcx.def_path_str(cid.instance.def_id())), - cid.promoted.map_or_else(String::new, |p| format!("::{p:?}")) ); // This can't use `init_stack_frame` since `body` is not a function, @@ -301,7 +300,7 @@ pub(crate) fn turn_into_const_value<'tcx>( which should have given a good error before ever invoking this function", ); assert!( - !is_static || cid.promoted.is_some(), + !is_static, "the `eval_to_const_value_raw` query should not be used for statics, use `eval_to_allocation` instead" ); @@ -328,7 +327,7 @@ pub fn eval_static_initializer_provider<'tcx>( assert!(tcx.is_static(def_id.to_def_id())); let instance = ty::Instance::mono(tcx, def_id.to_def_id()); - let cid = rustc_middle::mir::interpret::GlobalId { instance, promoted: None }; + let cid = rustc_middle::mir::interpret::GlobalId { instance }; eval_in_interpreter(tcx, cid, ty::TypingEnv::fully_monomorphized()) } @@ -358,7 +357,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>( ) -> ::rustc_middle::mir::interpret::EvalToAllocationRawResult<'tcx> { // This shouldn't be used for statics, since statics are conceptually places, // not values -- so what we do here could break pointer identity. - assert!(key.value.promoted.is_some() || !tcx.is_static(key.value.instance.def_id())); + assert!(!tcx.is_static(key.value.instance.def_id())); if cfg!(debug_assertions) { match key.typing_env.typing_mode() { @@ -409,8 +408,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>( let result = if let Some((value, ty)) = tcx.trivial_const(def) { eval_trivial_const_using_ecx(&mut ecx, cid, value, ty) } else { - ecx.load_mir(cid.instance.def, cid.promoted) - .and_then(|body| eval_body_using_ecx(&mut ecx, cid, body)) + ecx.load_mir(cid.instance.def).and_then(|body| eval_body_using_ecx(&mut ecx, cid, body)) }; result.report_err().map_err(|error| report_eval_error(&ecx, cid, error)) } diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 316bca5a258f1..2c321412fa5b5 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -450,7 +450,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { // This is a const fn. Call it. // In case of replacement, we return the *original* instance to make backtraces work out // (and we hope this does not confuse the FnAbi checks too much). - interp_ok(Some((ecx.load_mir(instance.def, None)?, orig_instance))) + interp_ok(Some((ecx.load_mir(instance.def)?, orig_instance))) } fn panic_nounwind(ecx: &mut InterpCx<'tcx, Self>, msg: &str) -> InterpResult<'tcx> { diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 7f247ccd7cd5c..14b2cfe87b099 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -311,9 +311,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { pub fn load_mir( &self, instance: ty::InstanceKind<'tcx>, - promoted: Option, ) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> { - trace!("load mir(instance={:?}, promoted={:?})", instance, promoted); + trace!("load mir(instance={:?})", instance); let body = M::load_mir(self, instance); // do not continue if typeck errors occurred (can only occur in local crate) if let Some(err) = body.tainted_by_errors { @@ -582,7 +581,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { &self, instance: ty::Instance<'tcx>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> { - let gid = GlobalId { instance, promoted: None }; + let gid = GlobalId { instance }; let val = if self.tcx.is_static(gid.instance.def_id()) { let alloc_id = self.tcx.reserve_and_set_static_alloc(gid.instance.def_id()); diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 9cadaef8f886b..2b8770ac42846 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -179,7 +179,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) { // FIXME(generic_const_items): Passing empty instead of identity args is fishy but // seems to be fine for now. Revisit this! let instance = ty::Instance::new_raw(item_def_id.into(), ty::GenericArgs::empty()); - let cid = GlobalId { instance, promoted: None }; + let cid = GlobalId { instance }; let typing_env = ty::TypingEnv::fully_monomorphized(); tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(cid)); } diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index 2e9cd31a13de0..a7e27c4ee75af 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -8,7 +8,7 @@ use rustc_type_ir::TypeVisitableExt; use super::interpret::ReportedErrorInfo; use crate::mir::interpret::{AllocId, AllocRange, ErrorHandled, GlobalAlloc, Scalar, alloc_range}; -use crate::mir::{Promoted, pretty_print_const_value}; +use crate::mir::pretty_print_const_value; use crate::ty::print::{pretty_print_const, with_no_trimmed_paths}; use crate::ty::{self, ConstKind, GenericArgsRef, ScalarInt, Ty, TyCtxt}; @@ -240,11 +240,7 @@ impl<'tcx> Const<'tcx> { def_id: DefId, ) -> ty::EarlyBinder<'tcx, Const<'tcx>> { ty::EarlyBinder::bind(Const::Unevaluated( - UnevaluatedConst { - def: def_id, - args: ty::GenericArgs::identity_for_item(tcx, def_id), - promoted: None, - }, + UnevaluatedConst { def: def_id, args: ty::GenericArgs::identity_for_item(tcx, def_id) }, tcx.type_of(def_id).skip_binder(), )) } @@ -462,13 +458,11 @@ impl<'tcx> Const<'tcx> { pub struct UnevaluatedConst<'tcx> { pub def: DefId, pub args: GenericArgsRef<'tcx>, - pub promoted: Option, } impl<'tcx> UnevaluatedConst<'tcx> { #[inline] pub fn shrink(self) -> ty::UnevaluatedConst<'tcx> { - assert_eq!(self.promoted, None); ty::UnevaluatedConst { def: self.def, args: self.args } } } @@ -476,7 +470,7 @@ impl<'tcx> UnevaluatedConst<'tcx> { impl<'tcx> UnevaluatedConst<'tcx> { #[inline] pub fn new(def: DefId, args: GenericArgsRef<'tcx>) -> UnevaluatedConst<'tcx> { - UnevaluatedConst { def, args, promoted: Default::default() } + UnevaluatedConst { def, args } } #[inline] @@ -497,11 +491,7 @@ impl<'tcx> Display for Const<'tcx> { // Matches `GlobalId` printing. let instance = with_no_trimmed_paths!(tcx.def_path_str_with_args(c.def, c.args)); - write!(fmt, "{instance}")?; - if let Some(promoted) = c.promoted { - write!(fmt, "::{promoted:?}")?; - } - Ok(()) + write!(fmt, "{instance}") }) } } diff --git a/compiler/rustc_middle/src/mir/interpret/mod.rs b/compiler/rustc_middle/src/mir/interpret/mod.rs index f4bd64e4ca211..8240fecb3efb8 100644 --- a/compiler/rustc_middle/src/mir/interpret/mod.rs +++ b/compiler/rustc_middle/src/mir/interpret/mod.rs @@ -42,7 +42,6 @@ pub use self::error::{ }; pub use self::pointer::{CtfeProvenance, Pointer, PointerArithmetic, Provenance}; pub use self::value::Scalar; -use crate::mir; use crate::ty::codec::{TyDecoder, TyEncoder}; use crate::ty::print::with_no_trimmed_paths; use crate::ty::{self, Instance, Ty, TyCtxt}; @@ -56,19 +55,11 @@ pub struct GlobalId<'tcx> { /// For a constant or static, the `Instance` of the item itself. /// For a promoted global, the `Instance` of the function they belong to. pub instance: ty::Instance<'tcx>, - - /// The index for promoted globals within their function's `mir::Body`. - pub promoted: Option, } impl<'tcx> GlobalId<'tcx> { pub fn display(self, tcx: TyCtxt<'tcx>) -> String { - let instance_name = with_no_trimmed_paths!(tcx.def_path_str(self.instance.def.def_id())); - if let Some(promoted) = self.promoted { - format!("{instance_name}::{promoted:?}") - } else { - instance_name - } + with_no_trimmed_paths!(tcx.def_path_str(self.instance.def.def_id())) } } diff --git a/compiler/rustc_middle/src/mir/interpret/queries.rs b/compiler/rustc_middle/src/mir/interpret/queries.rs index 00ac8e66cda75..f17c5b458f4cc 100644 --- a/compiler/rustc_middle/src/mir/interpret/queries.rs +++ b/compiler/rustc_middle/src/mir/interpret/queries.rs @@ -23,7 +23,7 @@ impl<'tcx> TyCtxt<'tcx> { // encountered. let args = GenericArgs::identity_for_item(self, def_id); let instance = ty::Instance::new_raw(def_id, args); - let cid = GlobalId { instance, promoted: None }; + let cid = GlobalId { instance }; let typing_env = ty::TypingEnv::post_analysis(self, def_id); self.const_eval_global_id(typing_env, cid, DUMMY_SP) } @@ -39,7 +39,7 @@ impl<'tcx> TyCtxt<'tcx> { // encountered. let args = GenericArgs::identity_for_item(self, def_id); let instance = ty::Instance::new_raw(def_id, args); - let cid = GlobalId { instance, promoted: None }; + let cid = GlobalId { instance }; let typing_env = ty::TypingEnv::post_analysis(self, def_id); let inputs = self.erase_and_anonymize_regions(typing_env.as_query_input(cid)); self.eval_to_allocation_raw(inputs) @@ -74,7 +74,7 @@ impl<'tcx> TyCtxt<'tcx> { // FIXME: maybe have a separate version for resolving mir::UnevaluatedConst? match ty::Instance::try_resolve(self, typing_env, ct.def, ct.args) { Ok(Some(instance)) => { - let cid = GlobalId { instance, promoted: ct.promoted }; + let cid = GlobalId { instance }; self.const_eval_global_id(typing_env, cid, span) } // For errors during resolution, we deliberately do not point at the usage site of the constant, @@ -104,7 +104,7 @@ impl<'tcx> TyCtxt<'tcx> { } let cid = match ty::Instance::try_resolve(self, typing_env, ct.def, ct.args) { - Ok(Some(instance)) => GlobalId { instance, promoted: None }, + Ok(Some(instance)) => GlobalId { instance }, // For errors during resolution, we deliberately do not point at the usage site of the constant, // since for these errors the place the constant is used shouldn't matter. Ok(None) => return Err(ErrorHandled::TooGeneric(DUMMY_SP).into()), @@ -160,7 +160,7 @@ impl<'tcx> TyCtxt<'tcx> { instance: ty::Instance<'tcx>, span: Span, ) -> EvalToConstValueResult<'tcx> { - self.const_eval_global_id(typing_env, GlobalId { instance, promoted: None }, span) + self.const_eval_global_id(typing_env, GlobalId { instance }, span) } /// Evaluate a constant to a `ConstValue`. diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 55ad46d5de45f..1faa83ca5b5a3 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -117,18 +117,15 @@ impl MirPhase { #[derive(StableHash, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)] pub struct MirSource<'tcx> { pub instance: InstanceKind<'tcx>, - - /// If `Some`, this is a promoted rvalue within the parent function. - pub promoted: Option, } impl<'tcx> MirSource<'tcx> { pub fn item(def_id: DefId) -> Self { - MirSource { instance: InstanceKind::Item(def_id), promoted: None } + MirSource { instance: InstanceKind::Item(def_id) } } pub fn from_instance(instance: InstanceKind<'tcx>) -> Self { - MirSource { instance, promoted: None } + MirSource { instance } } #[inline] @@ -1712,6 +1709,6 @@ mod size_asserts { static_assert_size!(SourceScopeData<'_>, 64); static_assert_size!(Statement<'_>, 56); static_assert_size!(Terminator<'_>, 96); - static_assert_size!(VarDebugInfo<'_>, 88); + static_assert_size!(VarDebugInfo<'_>, 80); // tidy-alphabetical-end } diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 095fefd43418e..8366551b65f07 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -637,9 +637,6 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io: // see notes on #41697 elsewhere write!(w, "{}", tcx.def_path_str(def_id))? } - if let Some(p) = body.source.promoted { - write!(w, "::{p:?}")?; - } if is_function { write!(w, "(")?; @@ -1450,12 +1447,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { | ty::ConstKind::Bound(..) => bug!("unexpected MIR constant: {:?}", const_), }, Const::Unevaluated(uv, _) => { - format!( - "Unevaluated({}, {:?}, {:?})", - self.tcx.def_path_str(uv.def), - uv.args, - uv.promoted, - ) + format!("Unevaluated({}, {:?})", self.tcx.def_path_str(uv.def), uv.args,) } Const::Val(val, ty) => format!("Value({})", fmt_val(*val, *ty)), }; diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index be8b02f61133d..cec702133338d 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -31,10 +31,6 @@ impl<'tcx> crate::MirPass<'tcx> for InstrumentCoverage { fn run_pass(&self, tcx: TyCtxt<'tcx>, mir_body: &mut mir::Body<'tcx>) { let mir_source = mir_body.source; - // This pass runs after MIR promotion, but before promoted MIR starts to - // be transformed, so it should never see promoted MIR. - assert!(mir_source.promoted.is_none()); - let def_id = mir_source.def_id().expect_local(); if !tcx.is_eligible_for_coverage(def_id) { diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index c7c6331a4011e..6b4005e8d50f7 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -958,7 +958,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let args = ty::InlineConstArgs::new(tcx, ty::InlineConstArgsParts { parent_args, ty: ref_ty }) .args; - let uneval = UnevaluatedConst { def: self.promoted.source.def_id(), args, promoted: None }; + let uneval = UnevaluatedConst { def: self.promoted.source.def_id(), args }; feeder.mir_promoted((tcx.alloc_steal_mir(self.promoted), tcx.arena.alloc(IndexVec::new()))); @@ -1061,7 +1061,7 @@ fn promote_candidates<'tcx>( IndexVec::new(), IndexVec::from_elem_n(scope, 1), initial_locals, - IndexVec::new(), + body.user_type_annotations.clone(), 0, vec![], body.span, diff --git a/compiler/rustc_public/src/ty.rs b/compiler/rustc_public/src/ty.rs index 59b4c6bee5c03..099f6cc8fd5d0 100644 --- a/compiler/rustc_public/src/ty.rs +++ b/compiler/rustc_public/src/ty.rs @@ -1401,7 +1401,6 @@ pub struct ParamConst { pub struct UnevaluatedConst { pub def: ConstDef, pub args: GenericArgs, - pub promoted: Option, } #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)] diff --git a/compiler/rustc_public/src/unstable/convert/stable/mir.rs b/compiler/rustc_public/src/unstable/convert/stable/mir.rs index 2bc23e2837048..1e37e24d19536 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/mir.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/mir.rs @@ -875,7 +875,6 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> { let kind = crate::ty::ConstantKind::Unevaluated(crate::ty::UnevaluatedConst { def: tables.const_def(unev_const.def), args: unev_const.args.stable(tables, cx), - promoted: unev_const.promoted.map(|u| u.as_u32()), }); let ty = ty.stable(tables, cx); MirConst::new(kind, ty, id) diff --git a/compiler/rustc_public/src/visitor.rs b/compiler/rustc_public/src/visitor.rs index acc3334769613..71f4b38a8b824 100644 --- a/compiler/rustc_public/src/visitor.rs +++ b/compiler/rustc_public/src/visitor.rs @@ -88,10 +88,9 @@ impl Visitable for Allocation { impl Visitable for UnevaluatedConst { fn super_visit(&self, visitor: &mut V) -> ControlFlow { - let UnevaluatedConst { def, args, promoted } = self; + let UnevaluatedConst { def, args } = self; def.visit(visitor)?; - args.visit(visitor)?; - promoted.visit(visitor) + args.visit(visitor) } } diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index 512ea6ab1a2ff..4ad7ca78f6948 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -397,7 +397,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let this = self.eval_context_mut(); // Get MIR. - let mir = this.load_mir(f.def, None)?; + let mir = this.load_mir(f.def)?; let dest = match dest { Some(dest) => dest.clone(), None => MPlaceTy::fake_alloc_zst(this.machine.layouts.unit), diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index a59ce648985c2..39ad4327bbb19 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -1257,7 +1257,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { // Otherwise, load the MIR. let _trace = enter_trace_span!("load_mir"); - interp_ok(Some((ecx.load_mir(instance.def, None)?, instance))) + interp_ok(Some((ecx.load_mir(instance.def)?, instance))) } #[inline(always)] diff --git a/src/tools/miri/src/shims/foreign_items.rs b/src/tools/miri/src/shims/foreign_items.rs index 1c2fdfeea44d1..0ee7e5b4f8882 100644 --- a/src/tools/miri/src/shims/foreign_items.rs +++ b/src/tools/miri/src/shims/foreign_items.rs @@ -238,7 +238,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { }; match instance { None => interp_ok(None), // no symbol with this name - Some(instance) => interp_ok(Some((this.load_mir(instance.def, None)?, instance))), + Some(instance) => interp_ok(Some((this.load_mir(instance.def)?, instance))), } } } From 714b18d3b0731f684b7b5e82eccb31b09a21fe8b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 18 May 2023 14:16:19 +0000 Subject: [PATCH 13/15] Retire MirSource. --- .../src/diagnostics/mutability_errors.rs | 4 +-- compiler/rustc_middle/src/mir/mod.rs | 29 +++---------------- compiler/rustc_middle/src/mir/pretty.rs | 4 +-- .../rustc_mir_build/src/builder/custom/mod.rs | 2 +- compiler/rustc_mir_build/src/builder/mod.rs | 6 ++-- .../src/check_packed_ref.rs | 2 +- .../src/coroutine/by_move_body.rs | 3 +- .../rustc_mir_transform/src/coroutine/drop.rs | 6 ++-- compiler/rustc_mir_transform/src/lint.rs | 2 +- .../rustc_mir_transform/src/promote_consts.rs | 2 +- compiler/rustc_mir_transform/src/shim.rs | 22 ++++++-------- .../src/shim/async_destructor_ctor.rs | 11 ++++--- compiler/rustc_mir_transform/src/validate.rs | 8 ++--- .../src/mono_checks/abi_check.rs | 2 +- 14 files changed, 38 insertions(+), 65 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 33bb4889ae22d..764b7df3085fb 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -1223,7 +1223,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { fn suggest_using_iter_mut(&self, err: &mut Diag<'_>) { let source = self.body.source; - if let InstanceKind::Item(def_id) = source.instance + if let InstanceKind::Item(def_id) = source && let Some(Node::Expr(hir::Expr { hir_id, kind, .. })) = self.infcx.tcx.hir_get_if_local(def_id) && let ExprKind::Closure(hir::Closure { kind: hir::ClosureKind::Closure, .. }) = kind @@ -1614,7 +1614,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } // Make sure we are inside a closure. - let InstanceKind::Item(body_def_id) = self.body.source.instance else { + let InstanceKind::Item(body_def_id) = self.body.source else { return false; }; let Some(Node::Expr(hir::Expr { hir_id: body_hir_id, kind, .. })) = diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 1faa83ca5b5a3..99800720851d1 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -112,28 +112,6 @@ impl MirPhase { } } -/// Where a specific `mir::Body` comes from. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -#[derive(StableHash, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)] -pub struct MirSource<'tcx> { - pub instance: InstanceKind<'tcx>, -} - -impl<'tcx> MirSource<'tcx> { - pub fn item(def_id: DefId) -> Self { - MirSource { instance: InstanceKind::Item(def_id) } - } - - pub fn from_instance(instance: InstanceKind<'tcx>) -> Self { - MirSource { instance } - } - - #[inline] - pub fn def_id(&self) -> DefId { - self.instance.def_id() - } -} - /// Additional information carried by a MIR body when it is lowered from a coroutine. /// This information is modified as it is lowered during the `StateTransform` MIR pass, /// so not all fields will be active at a given time. For example, the `yield_ty` is @@ -215,7 +193,8 @@ pub struct Body<'tcx> { /// How many passes we have executed since starting the current phase. Used for debug output. pub pass_count: usize, - pub source: MirSource<'tcx>, + /// Where this specific body comes from. + pub source: InstanceKind<'tcx>, /// A list of source scopes; these are referenced by statements /// and used for debuginfo. Indexed by a `SourceScope`. @@ -329,7 +308,7 @@ pub struct Body<'tcx> { impl<'tcx> Body<'tcx> { pub fn new( - source: MirSource<'tcx>, + source: InstanceKind<'tcx>, basic_blocks: IndexVec>, source_scopes: IndexVec>, local_decls: IndexVec>, @@ -382,7 +361,7 @@ impl<'tcx> Body<'tcx> { let mut body = Body { phase: MirPhase::Built, pass_count: 0, - source: MirSource::item(CRATE_DEF_ID.to_def_id()), + source: InstanceKind::Item(CRATE_DEF_ID.to_def_id()), basic_blocks: BasicBlocks::new(basic_blocks), source_scopes: IndexVec::new(), coroutine: None, diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 8366551b65f07..0272b74de6490 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -210,7 +210,7 @@ impl<'a, 'tcx> MirDumper<'a, 'tcx> { let item_name = tcx.def_path(source.def_id()).to_filename_friendly_no_crate(); // All drop shims have the same DefId, so we have to add the type // to get unique file names. - let shim_disambiguator = match source.instance { + let shim_disambiguator = match source { ty::InstanceKind::DropGlue(_, Some(ty)) => { // Unfortunately, pretty-printed types are not very filename-friendly. // We do some filtering. @@ -606,7 +606,7 @@ fn write_function_coverage_info( fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io::Result<()> { use rustc_hir::def::DefKind; - trace!("write_mir_sig: {:?}", body.source.instance); + trace!("write_mir_sig: {:?}", body.source); let def_id = body.source.def_id(); let kind = tcx.def_kind(def_id); let is_function = match kind { diff --git a/compiler/rustc_mir_build/src/builder/custom/mod.rs b/compiler/rustc_mir_build/src/builder/custom/mod.rs index 1005dd30d73f4..5872d0aa373db 100644 --- a/compiler/rustc_mir_build/src/builder/custom/mod.rs +++ b/compiler/rustc_mir_build/src/builder/custom/mod.rs @@ -44,7 +44,7 @@ pub(super) fn build_custom_mir<'tcx>( ) -> Body<'tcx> { let mut body = Body { basic_blocks: BasicBlocks::new(IndexVec::new()), - source: MirSource::item(did), + source: ty::InstanceKind::Item(did), phase: MirPhase::Built, source_scopes: IndexVec::new(), coroutine: None, diff --git a/compiler/rustc_mir_build/src/builder/mod.rs b/compiler/rustc_mir_build/src/builder/mod.rs index 5a33963b2b654..253908057fe9b 100644 --- a/compiler/rustc_mir_build/src/builder/mod.rs +++ b/compiler/rustc_mir_build/src/builder/mod.rs @@ -726,7 +726,7 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) - cfg.terminate(START_BLOCK, source_info, TerminatorKind::Unreachable); Body::new( - MirSource::item(def_id.to_def_id()), + ty::InstanceKind::Item(def_id.to_def_id()), cfg.basic_blocks, source_scopes, local_decls, @@ -807,7 +807,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { #[allow(dead_code)] fn dump_for_debugging(&self) { let mut body = Body::new( - MirSource::item(self.def_id.to_def_id()), + ty::InstanceKind::Item(self.def_id.to_def_id()), self.cfg.basic_blocks.clone(), self.source_scopes.clone(), self.local_decls.clone(), @@ -937,7 +937,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn finish(self) -> Body<'tcx> { let mut body = Body::new( - MirSource::item(self.def_id.to_def_id()), + ty::InstanceKind::Item(self.def_id.to_def_id()), self.cfg.basic_blocks, self.source_scopes, self.local_decls, diff --git a/compiler/rustc_mir_transform/src/check_packed_ref.rs b/compiler/rustc_mir_transform/src/check_packed_ref.rs index 9ce244a00fcec..c484210a20533 100644 --- a/compiler/rustc_mir_transform/src/check_packed_ref.rs +++ b/compiler/rustc_mir_transform/src/check_packed_ref.rs @@ -41,7 +41,7 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> { && let Some((adt, pack)) = util::place_unalignment(self.tcx, self.body, self.typing_env, *place) { - let def_id = self.body.source.instance.def_id(); + let def_id = self.body.source.def_id(); if let Some(impl_def_id) = self.tcx.trait_impl_of_assoc(def_id) && self.tcx.is_builtin_derived(impl_def_id) { diff --git a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs index cfe07081ee219..7b070bb8717fa 100644 --- a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs +++ b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs @@ -223,8 +223,7 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>( None, &mut PerParentDisambiguatorState::new(parent_def_id), ); - by_move_body.source = - mir::MirSource::from_instance(InstanceKind::Item(body_def.def_id().to_def_id())); + by_move_body.source = InstanceKind::Item(body_def.def_id().to_def_id()); if let Some(dumper) = MirDumper::new(tcx, "built", &by_move_body) { dumper.set_disambiguator(&"after").dump_mir(&by_move_body); diff --git a/compiler/rustc_mir_transform/src/coroutine/drop.rs b/compiler/rustc_mir_transform/src/coroutine/drop.rs index 2699a051a8fea..2c092ec52585a 100644 --- a/compiler/rustc_mir_transform/src/coroutine/drop.rs +++ b/compiler/rustc_mir_transform/src/coroutine/drop.rs @@ -605,17 +605,17 @@ pub(super) fn create_coroutine_drop_shim<'tcx>( simplify::remove_dead_blocks(&mut body); // Update the body's def to become the drop glue. - let coroutine_instance = body.source.instance; + let coroutine_instance = body.source; let drop_in_place = tcx.require_lang_item(LangItem::DropInPlace, body.span); let drop_instance = InstanceKind::DropGlue(drop_in_place, Some(coroutine_ty)); // Temporary change MirSource to coroutine's instance so that dump_mir produces more sensible // filename. - body.source.instance = coroutine_instance; + body.source = coroutine_instance; if let Some(dumper) = MirDumper::new(tcx, "coroutine_drop", &body) { dumper.dump_mir(&body); } - body.source.instance = drop_instance; + body.source = drop_instance; // Creating a coroutine drop shim happens on `Analysis(PostCleanup) -> Runtime(Initial)` // but the pass manager doesn't update the phase of the coroutine drop shim. Update the diff --git a/compiler/rustc_mir_transform/src/lint.rs b/compiler/rustc_mir_transform/src/lint.rs index e450e6754da13..ba50616aa9a95 100644 --- a/compiler/rustc_mir_transform/src/lint.rs +++ b/compiler/rustc_mir_transform/src/lint.rs @@ -57,7 +57,7 @@ impl<'a, 'tcx> Lint<'a, 'tcx> { span, format!( "broken MIR in {:?} ({}) at {:?}:\n{}", - self.body.source.instance, + self.body.source, self.when, location, msg.as_ref() diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index 6b4005e8d50f7..5f5e53a57d6ef 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -948,7 +948,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { feeder.feed_hir(); let def_id = feeder.def_id(); - self.promoted.source = MirSource::item(def_id.to_def_id()); + self.promoted.source = ty::InstanceKind::Item(def_id.to_def_id()); self.promoted.set_required_consts(self.required_consts); let parent_args = tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item( diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 39d5eef844559..59b07c452e706 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -354,7 +354,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) block(&mut blocks, TerminatorKind::Goto { target: return_block }); block(&mut blocks, TerminatorKind::Return); - let source = MirSource::from_instance(ty::InstanceKind::DropGlue(def_id, ty)); + let source = ty::InstanceKind::DropGlue(def_id, ty); let mut body = new_body(source, blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span); @@ -393,7 +393,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) } fn new_body<'tcx>( - source: MirSource<'tcx>, + source: ty::InstanceKind<'tcx>, basic_blocks: IndexVec>, local_decls: IndexVec>, arg_count: usize, @@ -523,7 +523,7 @@ fn build_thread_local_shim<'tcx>( )]); new_body( - MirSource::from_instance(instance), + instance, blocks, IndexVec::from_raw(vec![LocalDecl::new(tcx.thread_local_ptr_ty(def_id), span)]), 0, @@ -586,10 +586,7 @@ impl<'tcx> CloneShimBuilder<'tcx> { } fn into_mir(self) -> Body<'tcx> { - let source = MirSource::from_instance(ty::InstanceKind::CloneShim( - self.def_id, - self.sig.inputs_and_output[0], - )); + let source = ty::InstanceKind::CloneShim(self.def_id, self.sig.inputs_and_output[0]); new_body(source, self.blocks, self.local_decls, self.sig.inputs().len(), self.span) } @@ -1018,8 +1015,7 @@ fn build_call_shim<'tcx>( block(&mut blocks, vec![], TerminatorKind::UnwindResume, true); } - let mut body = - new_body(MirSource::from_instance(instance), blocks, local_decls, sig.inputs().len(), span); + let mut body = new_body(instance, blocks, local_decls, sig.inputs().len(), span); if let ExternAbi::RustCall = sig.abi() { body.spread_arg = Some(Local::new(sig.inputs().len())); @@ -1086,7 +1082,7 @@ pub(super) fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> { false, ); - let source = MirSource::item(ctor_id); + let source = ty::InstanceKind::Item(ctor_id); let mut body = new_body( source, IndexVec::from_elem_n(start_block, 1), @@ -1138,7 +1134,7 @@ fn build_fn_ptr_addr_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'t Some(Terminator { source_info, kind: TerminatorKind::Return }), false, ); - let source = MirSource::from_instance(ty::InstanceKind::FnPtrAddrShim(def_id, self_ty)); + let source = ty::InstanceKind::FnPtrAddrShim(def_id, self_ty); new_body(source, IndexVec::from_elem_n(start_block, 1), locals, sig.inputs().len(), span) } @@ -1237,10 +1233,10 @@ fn build_construct_coroutine_by_move_shim<'tcx>( false, ); - let source = MirSource::from_instance(ty::InstanceKind::ConstructCoroutineInClosureShim { + let source = ty::InstanceKind::ConstructCoroutineInClosureShim { coroutine_closure_def_id, receiver_by_ref, - }); + }; let body = new_body(source, IndexVec::from_elem_n(start_block, 1), locals, sig.inputs().len(), span); diff --git a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs index 0897aecb17e0a..897236548b7cf 100644 --- a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs +++ b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs @@ -3,8 +3,8 @@ use rustc_hir::lang_items::LangItem; use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource}; use rustc_index::{Idx, IndexVec}; use rustc_middle::mir::{ - BasicBlock, BasicBlockData, Body, Local, LocalDecl, MirSource, Operand, Place, Rvalue, - SourceInfo, Statement, StatementKind, Terminator, TerminatorKind, + BasicBlock, BasicBlockData, Body, Local, LocalDecl, Operand, Place, Rvalue, SourceInfo, + Statement, StatementKind, Terminator, TerminatorKind, }; use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeVisitableExt}; @@ -101,7 +101,7 @@ pub(super) fn build_async_drop_shim<'tcx>( ); block(&mut blocks, TerminatorKind::Return); - let source = MirSource::from_instance(ty::InstanceKind::AsyncDropGlue(def_id, ty)); + let source = ty::InstanceKind::AsyncDropGlue(def_id, ty); let mut body = new_body(source, blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span); @@ -208,7 +208,7 @@ fn build_adrop_for_coroutine_shim<'tcx>( let body = tcx.optimized_mir(*coroutine_def_id).future_drop_poll().unwrap(); let mut body: Body<'tcx> = EarlyBinder::bind(body.clone()).instantiate(tcx, impl_args).skip_norm_wip(); - body.source.instance = instance; + body.source = instance; body.phase = MirPhase::Runtime(RuntimePhase::Initial); body.var_debug_info.clear(); let pin_adt_ref = tcx.adt_def(tcx.require_lang_item(LangItem::Pin, span)); @@ -407,8 +407,7 @@ fn build_adrop_for_adrop_shim<'tcx>( false, )); - let source = MirSource::from_instance(instance); - let mut body = new_body(source, blocks, locals, sig.inputs().len(), span); + let mut body = new_body(instance, blocks, locals, sig.inputs().len(), span); body.phase = MirPhase::Runtime(RuntimePhase::Initial); return body; } diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index 995a14c67e66c..d4f99609aa9c6 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -40,7 +40,7 @@ impl<'tcx> crate::MirPass<'tcx> for Validator { // terribly important that they pass the validator. However, I think other passes might // still see them, in which case they might be surprised. It would probably be better if we // didn't put this through the MIR pipeline at all. - if matches!(body.source.instance, InstanceKind::Intrinsic(..) | InstanceKind::Virtual(..)) { + if matches!(body.source, InstanceKind::Intrinsic(..) | InstanceKind::Virtual(..)) { return; } let def_id = body.source.def_id(); @@ -88,7 +88,7 @@ impl<'tcx> crate::MirPass<'tcx> for Validator { } if let MirPhase::Runtime(_) = body.phase - && let ty::InstanceKind::Item(_) = body.source.instance + && let ty::InstanceKind::Item(_) = body.source && body.has_free_regions() { cfg_checker.fail( @@ -129,7 +129,7 @@ impl<'a, 'tcx> CfgChecker<'a, 'tcx> { span_bug!( self.body.source_info(location).span, "broken MIR in {:?} ({}) at {:?}:\n{}", - self.body.source.instance, + self.body.source, self.when, location, msg.as_ref(), @@ -534,7 +534,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> { self.body.span, format!( "broken MIR in {:?} ({}):\ninvalid source scope {:?}", - self.body.source.instance, self.when, scope, + self.body.source, self.when, scope, ), ); } diff --git a/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs b/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs index 10218523ca232..8e8c130a3a561 100644 --- a/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs +++ b/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs @@ -247,7 +247,7 @@ fn check_callees_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, body: &m ty::TypingEnv::fully_monomorphized(), ty::EarlyBinder::bind(callee_ty), ); - check_call_site_abi(tcx, callee_ty, body.source.instance, || { + check_call_site_abi(tcx, callee_ty, body.source, || { let loc = Location { block: bb, statement_index: body.basic_blocks[bb].statements.len(), From f2832e71436c725333e170abb8c580e3fff9a532 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 22 Jul 2023 10:55:25 +0000 Subject: [PATCH 14/15] Retire GlobalId. --- .../src/const_eval/eval_queries.rs | 80 +++++++++---------- .../src/const_eval/valtrees.rs | 6 +- .../src/interpret/eval_context.rs | 11 +-- compiler/rustc_hir_analysis/src/lib.rs | 4 +- compiler/rustc_middle/src/error.rs | 12 +-- .../rustc_middle/src/mir/interpret/mod.rs | 20 +---- .../rustc_middle/src/mir/interpret/queries.rs | 60 +++++--------- compiler/rustc_middle/src/queries.rs | 22 ++--- compiler/rustc_middle/src/query/keys.rs | 8 +- src/doc/rustc-dev-guide/src/const-eval.md | 4 +- src/tools/miri/tests/fail/layout_cycle.stderr | 2 +- .../defaults-cyclic-fail.stderr | 10 +-- ...onst-static-recursion-trait-default.stderr | 6 +- .../unevaluated-const-ice-119731.rs | 12 +-- .../unevaluated-const-ice-119731.stderr | 14 ++-- .../const-generics/issues/issue-90318.stderr | 4 +- tests/ui/consts/const-size_of-cycle.stderr | 4 +- tests/ui/generic-const-items/recursive.stderr | 2 +- tests/ui/layout/layout-cycle.stderr | 2 +- tests/ui/offset-of/inside-array-length.stderr | 2 +- .../unsatisfied-const-trait-bound.stderr | 6 +- 21 files changed, 117 insertions(+), 174 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 915dc3fae4a86..2ada37dfcc91e 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -8,7 +8,7 @@ use rustc_middle::mir::{self, ConstAlloc, ConstValue}; use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::layout::{HasTypingEnv, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_middle::{bug, throw_inval}; use rustc_span::Span; use rustc_span::def_id::LocalDefId; @@ -17,7 +17,7 @@ use tracing::{debug, instrument, trace}; use super::{CanAccessMutGlobal, CompileTimeInterpCx, CompileTimeMachine}; use crate::const_eval::CheckAlignment; use crate::interpret::{ - CtfeValidationMode, GlobalId, Immediate, InternError, InternKind, InterpCx, InterpErrorKind, + CtfeValidationMode, Immediate, InternError, InternKind, InterpCx, InterpErrorKind, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, ReturnContinuation, create_static_alloc, intern_const_alloc_recursive, interp_ok, throw_exhaust, }; @@ -25,12 +25,12 @@ use crate::{CTRL_C_RECEIVED, errors}; fn setup_for_eval<'tcx>( ecx: &mut CompileTimeInterpCx<'tcx>, - cid: GlobalId<'tcx>, + instance: Instance<'tcx>, layout: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, (InternKind, MPlaceTy<'tcx>)> { assert!(layout.is_sized()); - let intern_kind = match ecx.tcx.def_kind(cid.instance.def_id()) { + let intern_kind = match ecx.tcx.def_kind(instance.def_id()) { DefKind::Static { mutability, .. } => InternKind::Static(mutability), DefKind::Promoted => InternKind::Promoted, DefKind::Const { .. } @@ -42,7 +42,7 @@ fn setup_for_eval<'tcx>( }; let return_place = if let InternKind::Static(_) = intern_kind { - create_static_alloc(ecx, cid.instance.def_id().expect_local(), layout) + create_static_alloc(ecx, instance.def_id().expect_local(), layout) } else { ecx.allocate(layout, MemoryKind::Stack) }; @@ -53,23 +53,20 @@ fn setup_for_eval<'tcx>( #[instrument(level = "trace", skip(ecx, body))] fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>( ecx: &mut CompileTimeInterpCx<'tcx>, - cid: GlobalId<'tcx>, + instance: Instance<'tcx>, body: &'tcx mir::Body<'tcx>, ) -> InterpResult<'tcx, R> { let tcx = *ecx.tcx; let layout = - ecx.layout_of(body.bound_return_ty().instantiate(tcx, cid.instance.args).skip_norm_wip())?; - let (intern_kind, ret) = setup_for_eval(ecx, cid, layout)?; + ecx.layout_of(body.bound_return_ty().instantiate(tcx, instance.args).skip_norm_wip())?; + let (intern_kind, ret) = setup_for_eval(ecx, instance, layout)?; - trace!( - "eval_body_using_ecx: pushing stack frame for global: {}", - with_no_trimmed_paths!(ecx.tcx.def_path_str(cid.instance.def_id())), - ); + trace!("eval_body_using_ecx: pushing stack frame for global: {:?}", instance.def_id()); // This can't use `init_stack_frame` since `body` is not a function, // so computing its ABI would fail. It's also not worth it since there are no arguments to pass. ecx.push_stack_frame_raw( - cid.instance, + instance, body, &ret.clone().into(), ReturnContinuation::Stop { cleanup: false }, @@ -83,28 +80,28 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>( } } - intern_and_validate(ecx, cid, intern_kind, ret) + intern_and_validate(ecx, instance, intern_kind, ret) } #[instrument(level = "trace", skip(ecx))] fn eval_trivial_const_using_ecx<'tcx, R: InterpretationResult<'tcx>>( ecx: &mut CompileTimeInterpCx<'tcx>, - cid: GlobalId<'tcx>, + instance: Instance<'tcx>, val: ConstValue, ty: Ty<'tcx>, ) -> InterpResult<'tcx, R> { let layout = ecx.layout_of(ty)?; - let (intern_kind, return_place) = setup_for_eval(ecx, cid, layout)?; + let (intern_kind, return_place) = setup_for_eval(ecx, instance, layout)?; let opty = ecx.const_val_to_op(val, ty, Some(layout))?; ecx.copy_op(&opty, &return_place)?; - intern_and_validate(ecx, cid, intern_kind, return_place) + intern_and_validate(ecx, instance, intern_kind, return_place) } fn intern_and_validate<'tcx, R: InterpretationResult<'tcx>>( ecx: &mut CompileTimeInterpCx<'tcx>, - cid: GlobalId<'tcx>, + instance: Instance<'tcx>, intern_kind: InternKind, ret: MPlaceTy<'tcx>, ) -> InterpResult<'tcx, R> { @@ -112,7 +109,7 @@ fn intern_and_validate<'tcx, R: InterpretationResult<'tcx>>( let intern_result = intern_const_alloc_recursive(ecx, intern_kind, &ret); // Since evaluation had no errors, validate the resulting constant. - const_validate_mplace(ecx, &ret, cid)?; + const_validate_mplace(ecx, &ret, instance)?; // Only report this after validation, as validation produces much better diagnostics. // FIXME: ensure validation always reports this and stop making interning care about it. @@ -282,15 +279,15 @@ pub(super) fn op_to_const<'tcx>( pub(crate) fn turn_into_const_value<'tcx>( tcx: TyCtxt<'tcx>, constant: ConstAlloc<'tcx>, - key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>, + key: ty::PseudoCanonicalInput<'tcx, Instance<'tcx>>, ) -> ConstValue { - let cid = key.value; - let def_id = cid.instance.def.def_id(); + let instance = key.value; + let def_id = instance.def.def_id(); let is_static = tcx.is_static(def_id); // This is just accessing an already computed constant, so no need to check alignment here. let ecx = mk_eval_cx_to_read_const_val( tcx, - tcx.def_span(key.value.instance.def_id()), + tcx.def_span(instance.def_id()), key.typing_env, CanAccessMutGlobal::from(is_static), ); @@ -311,9 +308,9 @@ pub(crate) fn turn_into_const_value<'tcx>( #[instrument(skip(tcx), level = "debug")] pub fn eval_to_const_value_raw_provider<'tcx>( tcx: TyCtxt<'tcx>, - key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>, + key: ty::PseudoCanonicalInput<'tcx, Instance<'tcx>>, ) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> { - if let Some((value, _ty)) = tcx.trivial_const(key.value.instance.def_id()) { + if let Some((value, _ty)) = tcx.trivial_const(key.value.def_id()) { return Ok(value); } tcx.eval_to_allocation_raw(key).map(|val| turn_into_const_value(tcx, val, key)) @@ -327,8 +324,7 @@ pub fn eval_static_initializer_provider<'tcx>( assert!(tcx.is_static(def_id.to_def_id())); let instance = ty::Instance::mono(tcx, def_id.to_def_id()); - let cid = rustc_middle::mir::interpret::GlobalId { instance }; - eval_in_interpreter(tcx, cid, ty::TypingEnv::fully_monomorphized()) + eval_in_interpreter(tcx, instance, ty::TypingEnv::fully_monomorphized()) } pub trait InterpretationResult<'tcx> { @@ -353,11 +349,11 @@ impl<'tcx> InterpretationResult<'tcx> for ConstAlloc<'tcx> { #[instrument(skip(tcx), level = "debug")] pub fn eval_to_allocation_raw_provider<'tcx>( tcx: TyCtxt<'tcx>, - key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>, + key: ty::PseudoCanonicalInput<'tcx, Instance<'tcx>>, ) -> ::rustc_middle::mir::interpret::EvalToAllocationRawResult<'tcx> { // This shouldn't be used for statics, since statics are conceptually places, // not values -- so what we do here could break pointer identity. - assert!(!tcx.is_static(key.value.instance.def_id())); + assert!(!tcx.is_static(key.value.def_id())); if cfg!(debug_assertions) { match key.typing_env.typing_mode() { @@ -377,7 +373,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>( // The next two lines concatenated contain some discussion: // https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/ // subject/anon_const_instance_printing/near/135980032 - let instance = with_no_trimmed_paths!(key.value.instance.to_string()); + let instance = with_no_trimmed_paths!(key.value.to_string()); trace!("const eval: {:?} ({})", key, instance); } @@ -386,10 +382,10 @@ pub fn eval_to_allocation_raw_provider<'tcx>( fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>( tcx: TyCtxt<'tcx>, - cid: GlobalId<'tcx>, + instance: Instance<'tcx>, typing_env: ty::TypingEnv<'tcx>, ) -> Result { - let def = cid.instance.def.def_id(); + let def = instance.def.def_id(); // `type const` don't have bodys debug_assert!(!tcx.is_type_const(def), "CTFE tried to evaluate type-const: {:?}", def); @@ -406,24 +402,24 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>( ); let result = if let Some((value, ty)) = tcx.trivial_const(def) { - eval_trivial_const_using_ecx(&mut ecx, cid, value, ty) + eval_trivial_const_using_ecx(&mut ecx, instance, value, ty) } else { - ecx.load_mir(cid.instance.def).and_then(|body| eval_body_using_ecx(&mut ecx, cid, body)) + ecx.load_mir(instance.def).and_then(|body| eval_body_using_ecx(&mut ecx, instance, body)) }; - result.report_err().map_err(|error| report_eval_error(&ecx, cid, error)) + result.report_err().map_err(|error| report_eval_error(&ecx, instance, error)) } #[inline(always)] fn const_validate_mplace<'tcx>( ecx: &mut InterpCx<'tcx, CompileTimeMachine<'tcx>>, mplace: &MPlaceTy<'tcx>, - cid: GlobalId<'tcx>, + instance: Instance<'tcx>, ) -> Result<(), ErrorHandled> { let alloc_id = mplace.ptr().provenance.unwrap().alloc_id(); let mut ref_tracking = RefTracking::new(mplace.clone(), mplace.layout.ty); let mut inner = false; while let Some((mplace, path)) = ref_tracking.next() { - let mode = match ecx.tcx.def_kind(cid.instance.def_id()) { + let mode = match ecx.tcx.def_kind(instance.def_id()) { DefKind::Promoted => CtfeValidationMode::Promoted, // a `static` DefKind::Static { mutability, .. } => CtfeValidationMode::Static { mutbl: mutability }, @@ -436,7 +432,7 @@ fn const_validate_mplace<'tcx>( .report_err() // Instead of just reporting the `InterpError` via the usual machinery, we give a more targeted // error about the validation failure. - .map_err(|error| report_validation_error(&ecx, cid, error, alloc_id))?; + .map_err(|error| report_validation_error(&ecx, instance, error, alloc_id))?; inner = true; } @@ -446,7 +442,7 @@ fn const_validate_mplace<'tcx>( #[inline(never)] fn report_eval_error<'tcx>( ecx: &InterpCx<'tcx, CompileTimeMachine<'tcx>>, - cid: GlobalId<'tcx>, + instance: Instance<'tcx>, error: InterpErrorInfo<'tcx>, ) -> ErrorHandled { let (error, backtrace) = error.into_parts(); @@ -458,7 +454,7 @@ fn report_eval_error<'tcx>( span, format!( "evaluation of `{instance}` failed {where_}", - instance = with_no_trimmed_paths!(cid.instance.to_string()), + instance = with_no_trimmed_paths!(instance.to_string()), where_ = if num_frames == 0 { "here" } else { "inside this call" }, ), ); @@ -471,13 +467,13 @@ fn report_eval_error<'tcx>( #[inline(never)] fn report_validation_error<'tcx>( ecx: &InterpCx<'tcx, CompileTimeMachine<'tcx>>, - cid: GlobalId<'tcx>, + instance: Instance<'tcx>, error: InterpErrorInfo<'tcx>, alloc_id: AllocId, ) -> ErrorHandled { if !matches!(error.kind(), InterpErrorKind::UndefinedBehavior(_)) { // Some other error happened during validation, e.g. an unsupported operation. - return report_eval_error(ecx, cid, error); + return report_eval_error(ecx, instance, error); } let (error, backtrace) = error.into_parts(); diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index 9e23f56d372b2..ffe74cc23d1cc 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -1,6 +1,6 @@ use rustc_abi::{BackendRepr, FieldIdx, VariantIdx}; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId, ValTreeCreationError}; +use rustc_middle::mir::interpret::{EvalToValTreeResult, ValTreeCreationError}; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::layout::{LayoutCx, TyAndLayout}; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -234,7 +234,7 @@ fn create_valtree_place<'tcx>( pub(crate) fn eval_to_valtree<'tcx>( tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>, - cid: GlobalId<'tcx>, + instance: ty::Instance<'tcx>, ) -> EvalToValTreeResult<'tcx> { if cfg!(debug_assertions) { match typing_env.typing_mode() { @@ -249,7 +249,7 @@ pub(crate) fn eval_to_valtree<'tcx>( } } } - let const_alloc = tcx.eval_to_allocation_raw(typing_env.as_query_input(cid))?; + let const_alloc = tcx.eval_to_allocation_raw(typing_env.as_query_input(instance))?; // FIXME Need to provide a span to `eval_to_valtree` let ecx = mk_eval_cx_to_read_const_val( diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 14b2cfe87b099..08307100d3bec 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -18,7 +18,7 @@ use rustc_target::callconv::FnAbi; use tracing::{debug, trace}; use super::{ - Frame, FrameInfo, GlobalId, InterpErrorInfo, InterpErrorKind, InterpResult, MPlaceTy, Machine, + Frame, FrameInfo, InterpErrorInfo, InterpErrorKind, InterpResult, MPlaceTy, Machine, MemPlaceMeta, Memory, OpTy, Place, PlaceTy, PointerArithmetic, Projectable, Provenance, err_inval, interp_ok, throw_inval, throw_ub, throw_ub_format, }; @@ -581,14 +581,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { &self, instance: ty::Instance<'tcx>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> { - let gid = GlobalId { instance }; - let val = if self.tcx.is_static(gid.instance.def_id()) { - let alloc_id = self.tcx.reserve_and_set_static_alloc(gid.instance.def_id()); + let val = if self.tcx.is_static(instance.def_id()) { + let alloc_id = self.tcx.reserve_and_set_static_alloc(instance.def_id()); let ty = instance.ty(self.tcx.tcx, self.typing_env); mir::ConstAlloc { alloc_id, ty } } else { - self.ctfe_query(|tcx| tcx.eval_to_allocation_raw(self.typing_env.as_query_input(gid)))? + self.ctfe_query(|tcx| { + tcx.eval_to_allocation_raw(self.typing_env.as_query_input(instance)) + })? }; self.raw_const_to_mplace(val) } diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 2b8770ac42846..2945c51652b1d 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -85,7 +85,6 @@ pub use errors::NoVariantNamed; use rustc_abi::{CVariadicStatus, ExternAbi}; use rustc_hir as hir; use rustc_hir::def::DefKind; -use rustc_middle::mir::interpret::GlobalId; use rustc_middle::query::Providers; use rustc_middle::ty::{Const, Ty, TyCtxt}; use rustc_middle::{middle, ty}; @@ -179,9 +178,8 @@ pub fn check_crate(tcx: TyCtxt<'_>) { // FIXME(generic_const_items): Passing empty instead of identity args is fishy but // seems to be fine for now. Revisit this! let instance = ty::Instance::new_raw(item_def_id.into(), ty::GenericArgs::empty()); - let cid = GlobalId { instance }; let typing_env = ty::TypingEnv::fully_monomorphized(); - tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(cid)); + tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(instance)); } _ => (), } diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index 29ec97a6ca592..6ef152c78373a 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -116,20 +116,20 @@ pub(crate) struct TypeLengthLimit<'tcx> { } #[derive(Diagnostic)] -#[diag("maximum number of nodes exceeded in constant {$global_const_id}")] -pub(crate) struct MaxNumNodesInValtree { +#[diag("maximum number of nodes exceeded in constant {$instance}")] +pub(crate) struct MaxNumNodesInValtree<'tcx> { #[primary_span] pub span: Span, - pub global_const_id: String, + pub instance: Instance<'tcx>, } #[derive(Diagnostic)] -#[diag("constant {$global_const_id} cannot be used as pattern")] +#[diag("constant {$instance} cannot be used as pattern")] #[note("constants that reference mutable or external memory cannot be used as patterns")] -pub(crate) struct InvalidConstInValtree { +pub(crate) struct InvalidConstInValtree<'tcx> { #[primary_span] pub span: Span, - pub global_const_id: String, + pub instance: Instance<'tcx>, } #[derive(Diagnostic)] diff --git a/compiler/rustc_middle/src/mir/interpret/mod.rs b/compiler/rustc_middle/src/mir/interpret/mod.rs index 8240fecb3efb8..64be05d34de9b 100644 --- a/compiler/rustc_middle/src/mir/interpret/mod.rs +++ b/compiler/rustc_middle/src/mir/interpret/mod.rs @@ -19,7 +19,7 @@ use rustc_data_structures::sharded::ShardedHashMap; use rustc_data_structures::sync::{AtomicU64, Lock}; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_macros::{StableHash, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; +use rustc_macros::{StableHash, TyDecodable, TyEncodable}; use rustc_serialize::{Decodable, Encodable}; use tracing::{debug, trace}; // Also make the error macros available from this module. @@ -43,26 +43,8 @@ pub use self::error::{ pub use self::pointer::{CtfeProvenance, Pointer, PointerArithmetic, Provenance}; pub use self::value::Scalar; use crate::ty::codec::{TyDecoder, TyEncoder}; -use crate::ty::print::with_no_trimmed_paths; use crate::ty::{self, Instance, Ty, TyCtxt}; -/// Uniquely identifies one of the following: -/// - A constant -/// - A static -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, TyEncodable, TyDecodable)] -#[derive(StableHash, TypeFoldable, TypeVisitable)] -pub struct GlobalId<'tcx> { - /// For a constant or static, the `Instance` of the item itself. - /// For a promoted global, the `Instance` of the function they belong to. - pub instance: ty::Instance<'tcx>, -} - -impl<'tcx> GlobalId<'tcx> { - pub fn display(self, tcx: TyCtxt<'tcx>) -> String { - with_no_trimmed_paths!(tcx.def_path_str(self.instance.def.def_id())) - } -} - #[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct AllocId(pub NonZero); diff --git a/compiler/rustc_middle/src/mir/interpret/queries.rs b/compiler/rustc_middle/src/mir/interpret/queries.rs index f17c5b458f4cc..26a8728960fa6 100644 --- a/compiler/rustc_middle/src/mir/interpret/queries.rs +++ b/compiler/rustc_middle/src/mir/interpret/queries.rs @@ -4,9 +4,7 @@ use rustc_session::lint; use rustc_span::{DUMMY_SP, Span}; use tracing::{debug, instrument}; -use super::{ - ErrorHandled, EvalToAllocationRawResult, EvalToConstValueResult, GlobalId, ReportedErrorInfo, -}; +use super::{ErrorHandled, EvalToAllocationRawResult, EvalToConstValueResult, ReportedErrorInfo}; use crate::mir::interpret::ValTreeCreationError; use crate::ty::{self, ConstToValTreeResult, GenericArgs, TyCtxt, TypeVisitableExt}; use crate::{error, mir}; @@ -23,9 +21,8 @@ impl<'tcx> TyCtxt<'tcx> { // encountered. let args = GenericArgs::identity_for_item(self, def_id); let instance = ty::Instance::new_raw(def_id, args); - let cid = GlobalId { instance }; let typing_env = ty::TypingEnv::post_analysis(self, def_id); - self.const_eval_global_id(typing_env, cid, DUMMY_SP) + self.const_eval_instance(typing_env, instance, DUMMY_SP) } /// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts @@ -39,9 +36,8 @@ impl<'tcx> TyCtxt<'tcx> { // encountered. let args = GenericArgs::identity_for_item(self, def_id); let instance = ty::Instance::new_raw(def_id, args); - let cid = GlobalId { instance }; let typing_env = ty::TypingEnv::post_analysis(self, def_id); - let inputs = self.erase_and_anonymize_regions(typing_env.as_query_input(cid)); + let inputs = self.erase_and_anonymize_regions(typing_env.as_query_input(instance)); self.eval_to_allocation_raw(inputs) } @@ -73,10 +69,7 @@ impl<'tcx> TyCtxt<'tcx> { // FIXME: maybe have a separate version for resolving mir::UnevaluatedConst? match ty::Instance::try_resolve(self, typing_env, ct.def, ct.args) { - Ok(Some(instance)) => { - let cid = GlobalId { instance }; - self.const_eval_global_id(typing_env, cid, span) - } + Ok(Some(instance)) => self.const_eval_instance(typing_env, instance, span), // For errors during resolution, we deliberately do not point at the usage site of the constant, // since for these errors the place the constant is used shouldn't matter. Ok(None) => Err(ErrorHandled::TooGeneric(DUMMY_SP)), @@ -103,8 +96,8 @@ impl<'tcx> TyCtxt<'tcx> { bug!("did not expect inference variables here"); } - let cid = match ty::Instance::try_resolve(self, typing_env, ct.def, ct.args) { - Ok(Some(instance)) => GlobalId { instance }, + let instance = match ty::Instance::try_resolve(self, typing_env, ct.def, ct.args) { + Ok(Some(instance)) => instance, // For errors during resolution, we deliberately do not point at the usage site of the constant, // since for these errors the place the constant is used shouldn't matter. Ok(None) => return Err(ErrorHandled::TooGeneric(DUMMY_SP).into()), @@ -117,7 +110,7 @@ impl<'tcx> TyCtxt<'tcx> { } }; - self.const_eval_global_id_for_typeck(typing_env, cid, span).inspect(|_| { + self.const_eval_instance_for_typeck(typing_env, instance, span).inspect(|_| { // We are emitting the lint here instead of in `is_const_evaluatable` // as we normalize obligations before checking them, and normalization // uses this function to evaluate this constant. @@ -133,10 +126,10 @@ impl<'tcx> TyCtxt<'tcx> { // // If we don't *only* FCW anon consts we can wind up incorrectly FCW'ing uses of assoc // consts in pattern positions. #140447 - && self.def_kind(cid.instance.def_id()) == DefKind::AnonConst - && !self.is_trivial_const(cid.instance.def_id()) + && self.def_kind(instance.def_id()) == DefKind::AnonConst + && !self.is_trivial_const(instance.def_id()) { - let mir_body = self.mir_for_ctfe(cid.instance.def_id()); + let mir_body = self.mir_for_ctfe(instance.def_id()); if mir_body.is_polymorphic { let Some(local_def_id) = ct.def.as_local() else { return }; self.emit_node_span_lint( @@ -154,27 +147,18 @@ impl<'tcx> TyCtxt<'tcx> { }) } - pub fn const_eval_instance( - self, - typing_env: ty::TypingEnv<'tcx>, - instance: ty::Instance<'tcx>, - span: Span, - ) -> EvalToConstValueResult<'tcx> { - self.const_eval_global_id(typing_env, GlobalId { instance }, span) - } - /// Evaluate a constant to a `ConstValue`. #[instrument(skip(self), level = "debug")] - pub fn const_eval_global_id( + pub fn const_eval_instance( self, typing_env: ty::TypingEnv<'tcx>, - cid: GlobalId<'tcx>, + instance: ty::Instance<'tcx>, span: Span, ) -> EvalToConstValueResult<'tcx> { // Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should // improve caching of queries. let inputs = self.erase_and_anonymize_regions( - typing_env.with_post_analysis_normalized(self).as_query_input(cid), + typing_env.with_post_analysis_normalized(self).as_query_input(instance), ); if !span.is_dummy() { // The query doesn't know where it is being invoked, so we need to fix the span. @@ -186,16 +170,16 @@ impl<'tcx> TyCtxt<'tcx> { /// Evaluate a constant to a type-level constant. #[instrument(skip(self), level = "debug")] - pub fn const_eval_global_id_for_typeck( + pub fn const_eval_instance_for_typeck( self, typing_env: ty::TypingEnv<'tcx>, - cid: GlobalId<'tcx>, + instance: ty::Instance<'tcx>, span: Span, ) -> ConstToValTreeResult<'tcx> { // Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should // improve caching of queries. let inputs = self.erase_and_anonymize_regions( - typing_env.with_post_analysis_normalized(self).as_query_input(cid), + typing_env.with_post_analysis_normalized(self).as_query_input(instance), ); debug!(?inputs); let res = if !span.is_dummy() { @@ -212,17 +196,13 @@ impl<'tcx> TyCtxt<'tcx> { ValTreeCreationError::NonSupportedType(ty) => Ok(Err(ty)), // Report the others. ValTreeCreationError::NodesOverflow => { - let handled = self.dcx().emit_err(error::MaxNumNodesInValtree { - span, - global_const_id: cid.display(self), - }); + let handled = + self.dcx().emit_err(error::MaxNumNodesInValtree { span, instance }); Err(ReportedErrorInfo::allowed_in_infallible(handled).into()) } ValTreeCreationError::InvalidConst => { - let handled = self.dcx().emit_err(error::InvalidConstInValtree { - span, - global_const_id: cid.display(self), - }); + let handled = + self.dcx().emit_err(error::InvalidConstInValtree { span, instance }); Err(ReportedErrorInfo::allowed_in_infallible(handled).into()) } ValTreeCreationError::ErrorHandled(handled) => Err(handled), diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index 99cdd53a7ec07..b6055fcd35162 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -96,7 +96,7 @@ use crate::middle::resolve_bound_vars::{ObjectLifetimeDefault, ResolveBoundVars, use crate::middle::stability::DeprecationEntry; use crate::mir::interpret::{ EvalStaticInitializerRawResult, EvalToAllocationRawResult, EvalToConstValueResult, - EvalToValTreeResult, GlobalId, + EvalToValTreeResult, }; use crate::mono::{ CodegenUnit, CollectionMode, MonoItem, MonoItemPartitions, NormalizationErrorInMono, @@ -1329,12 +1329,9 @@ rustc_queries! { /// [`Self::eval_to_valtree`] instead. /// /// - query eval_to_allocation_raw(key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>) + query eval_to_allocation_raw(key: ty::PseudoCanonicalInput<'tcx, ty::Instance<'tcx>>) -> EvalToAllocationRawResult<'tcx> { - desc { - "const-evaluating + checking `{}`", - key.value.display(tcx) - } + desc { "const-evaluating + checking `{}`", key.value } cache_on_disk } @@ -1355,18 +1352,15 @@ rustc_queries! { ///
/// /// **Do not call this** directly, use one of the following wrappers: - /// [`TyCtxt::const_eval_poly`], [`TyCtxt::const_eval_resolve`], - /// [`TyCtxt::const_eval_instance`], or [`TyCtxt::const_eval_global_id`]. + /// [`TyCtxt::const_eval_poly`], [`TyCtxt::const_eval_resolve`] or + /// [`TyCtxt::const_eval_instance`]. /// ///
/// /// [^1]: Such as enum variant explicit discriminants or array lengths. - query eval_to_const_value_raw(key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>) + query eval_to_const_value_raw(key: ty::PseudoCanonicalInput<'tcx, ty::Instance<'tcx>>) -> EvalToConstValueResult<'tcx> { - desc { - "simplifying constant for the type system `{}`", - key.value.display(tcx) - } + desc { "simplifying constant for the type system `{}`", key.value } depth_limit cache_on_disk } @@ -1374,7 +1368,7 @@ rustc_queries! { /// Evaluate a constant and convert it to a type level constant or /// return `None` if that is not possible. query eval_to_valtree( - key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>> + key: ty::PseudoCanonicalInput<'tcx, ty::Instance<'tcx>> ) -> EvalToValTreeResult<'tcx> { desc { "evaluating type-level constant" } } diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 5c92f126e116c..83eb6cb9927ab 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -14,10 +14,10 @@ use crate::dep_graph::DepNodeIndex; use crate::infer::canonical::CanonicalQueryInput; use crate::mono::CollectionMode; use crate::query::{DefIdCache, DefaultCache, SingleCache, VecCache}; +use crate::traits; use crate::ty::fast_reject::SimplifiedType; use crate::ty::layout::ValidityRequirement; use crate::ty::{self, GenericArg, GenericArgsRef, Ty, TyCtxt}; -use crate::{mir, traits}; /// Placeholder for `CrateNum`'s "local" counterpart #[derive(Copy, Clone, Debug)] @@ -74,12 +74,6 @@ impl<'tcx> QueryKey for ty::Instance<'tcx> { } } -impl<'tcx> QueryKey for mir::interpret::GlobalId<'tcx> { - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - self.instance.default_span(tcx) - } -} - impl<'tcx> QueryKey for (Ty<'tcx>, Option>) { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP diff --git a/src/doc/rustc-dev-guide/src/const-eval.md b/src/doc/rustc-dev-guide/src/const-eval.md index a3fee034ec6ed..ebc015a32d4c6 100644 --- a/src/doc/rustc-dev-guide/src/const-eval.md +++ b/src/doc/rustc-dev-guide/src/const-eval.md @@ -27,9 +27,9 @@ done to precompute expressions to be used at runtime. Constant evaluation can be done by calling the `const_eval_*` functions of `TyCtxt`. They're the wrappers of the `const_eval` query. -* `const_eval_global_id_for_typeck` evaluates a constant to a valtree, +* `const_eval_instance_for_typeck` evaluates a constant to a valtree, so the result value can be further inspected by the compiler. -* `const_eval_global_id` evaluate a constant to an "opaque blob" containing its final value; +* `const_eval_instance` evaluate a constant to an "opaque blob" containing its final value; this is only useful for codegen backends and the CTFE evaluator engine itself. * `eval_static_initializer` specifically computes the initial values of a static. Statics are special; all other functions do not represent statics correctly diff --git a/src/tools/miri/tests/fail/layout_cycle.stderr b/src/tools/miri/tests/fail/layout_cycle.stderr index f8d555e5a10b8..438af0be57eb7 100644 --- a/src/tools/miri/tests/fail/layout_cycle.stderr +++ b/src/tools/miri/tests/fail/layout_cycle.stderr @@ -2,7 +2,7 @@ error[E0391]: cycle detected when computing layout of `S>` | = note: ...which requires computing layout of ` as Tr>::I`... = note: ...which again requires computing layout of `S>`, completing the cycle -note: cycle used when const-evaluating + checking `core::mem::SizedTypeProperties::SIZE` +note: cycle used when const-evaluating + checking `> as core::mem::SizedTypeProperties>::SIZE` --> RUSTLIB/core/src/mem/mod.rs:LL:CC | LL | const SIZE: usize = intrinsics::size_of::(); diff --git a/tests/ui/associated-consts/defaults-cyclic-fail.stderr b/tests/ui/associated-consts/defaults-cyclic-fail.stderr index f9ed838940f4a..428d512ce20c3 100644 --- a/tests/ui/associated-consts/defaults-cyclic-fail.stderr +++ b/tests/ui/associated-consts/defaults-cyclic-fail.stderr @@ -1,25 +1,25 @@ -error[E0391]: cycle detected when simplifying constant for the type system `Tr::A` +error[E0391]: cycle detected when simplifying constant for the type system `<() as Tr>::A` --> $DIR/defaults-cyclic-fail.rs:5:5 | LL | const A: u8 = Self::B; | ^^^^^^^^^^^ | -note: ...which requires const-evaluating + checking `Tr::A`... +note: ...which requires const-evaluating + checking `<() as Tr>::A`... --> $DIR/defaults-cyclic-fail.rs:5:19 | LL | const A: u8 = Self::B; | ^^^^^^^ -note: ...which requires simplifying constant for the type system `Tr::B`... +note: ...which requires simplifying constant for the type system `<() as Tr>::B`... --> $DIR/defaults-cyclic-fail.rs:8:5 | LL | const B: u8 = Self::A; | ^^^^^^^^^^^ -note: ...which requires const-evaluating + checking `Tr::B`... +note: ...which requires const-evaluating + checking `<() as Tr>::B`... --> $DIR/defaults-cyclic-fail.rs:8:19 | LL | const B: u8 = Self::A; | ^^^^^^^ - = note: ...which again requires simplifying constant for the type system `Tr::A`, completing the cycle + = note: ...which again requires simplifying constant for the type system `<() as Tr>::A`, completing the cycle note: cycle used when elaborating drops for `main::{promoted#1}` --> $DIR/defaults-cyclic-fail.rs:16:16 | diff --git a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr index d0ada37b99edd..581a8a0b599dd 100644 --- a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr +++ b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr @@ -19,18 +19,18 @@ note: ...which requires const-evaluating + checking `DEFAULT_REF_BAR`... | LL | const DEFAULT_REF_BAR: u32 = ::BAR; | ^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires simplifying constant for the type system `FooDefault::BAR`... +note: ...which requires simplifying constant for the type system `::BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5 | LL | const BAR: u32 = DEFAULT_REF_BAR; | ^^^^^^^^^^^^^^ -note: ...which requires const-evaluating + checking `FooDefault::BAR`... +note: ...which requires const-evaluating + checking `::BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5 | LL | const BAR: u32 = DEFAULT_REF_BAR; | ^^^^^^^^^^^^^^ = note: ...which again requires caching mir of `FooDefault::BAR` for CTFE, completing the cycle -note: cycle used when const-evaluating + checking `FooDefault::BAR` +note: cycle used when const-evaluating + checking `::BAR` --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5 | LL | const BAR: u32 = DEFAULT_REF_BAR; diff --git a/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.rs b/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.rs index 02a95ed3e9082..963e1e3d0495d 100644 --- a/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.rs +++ b/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.rs @@ -26,12 +26,12 @@ mod v20 { } impl v17 { - //~^ ERROR maximum number of nodes exceeded in constant v20::v17::::{constant#0} - //~| ERROR maximum number of nodes exceeded in constant v20::v17::::{constant#0} - //~| ERROR maximum number of nodes exceeded in constant v20::v17::::{constant#0} - //~| ERROR maximum number of nodes exceeded in constant v20::v17::::{constant#0} - //~| ERROR maximum number of nodes exceeded in constant v20::v17::::{constant#0} - //~| ERROR maximum number of nodes exceeded in constant v20::v17::::{constant#0} + //~^ ERROR maximum number of nodes exceeded in constant v17::::{constant#0} + //~| ERROR maximum number of nodes exceeded in constant v17::::{constant#0} + //~| ERROR maximum number of nodes exceeded in constant v17::<512, v2>::{constant#0} + //~| ERROR maximum number of nodes exceeded in constant v17::<512, v2>::{constant#0} + //~| ERROR maximum number of nodes exceeded in constant v17::<512, v2>::{constant#0} + //~| ERROR maximum number of nodes exceeded in constant v17::<512, v2>::{constant#0} pub const fn v21() -> v18 { //~^ ERROR cannot find type `v18` in this scope v18 { _p: () } diff --git a/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.stderr b/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.stderr index 022074181cecd..abd7628fe530f 100644 --- a/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.stderr +++ b/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.stderr @@ -93,13 +93,13 @@ error[E0425]: cannot find function `v6` in this scope LL | const v0: [[usize; v4]; v4] = v6(v8); | ^^ not found in this scope -error: maximum number of nodes exceeded in constant v20::v17::::{constant#0} +error: maximum number of nodes exceeded in constant v17::::{constant#0} --> $DIR/unevaluated-const-ice-119731.rs:28:37 | LL | impl v17 { | ^^ -error: maximum number of nodes exceeded in constant v20::v17::::{constant#0} +error: maximum number of nodes exceeded in constant v17::::{constant#0} --> $DIR/unevaluated-const-ice-119731.rs:28:37 | LL | impl v17 { @@ -107,15 +107,13 @@ LL | impl v17 { | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: maximum number of nodes exceeded in constant v20::v17::::{constant#0} +error: maximum number of nodes exceeded in constant v17::<512, v2>::{constant#0} --> $DIR/unevaluated-const-ice-119731.rs:28:37 | LL | impl v17 { | ^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: maximum number of nodes exceeded in constant v20::v17::::{constant#0} +error: maximum number of nodes exceeded in constant v17::<512, v2>::{constant#0} --> $DIR/unevaluated-const-ice-119731.rs:28:37 | LL | impl v17 { @@ -123,7 +121,7 @@ LL | impl v17 { | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: maximum number of nodes exceeded in constant v20::v17::::{constant#0} +error: maximum number of nodes exceeded in constant v17::<512, v2>::{constant#0} --> $DIR/unevaluated-const-ice-119731.rs:28:37 | LL | impl v17 { @@ -131,7 +129,7 @@ LL | impl v17 { | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: maximum number of nodes exceeded in constant v20::v17::::{constant#0} +error: maximum number of nodes exceeded in constant v17::<512, v2>::{constant#0} --> $DIR/unevaluated-const-ice-119731.rs:28:37 | LL | impl v17 { diff --git a/tests/ui/const-generics/issues/issue-90318.stderr b/tests/ui/const-generics/issues/issue-90318.stderr index 05029844a9654..ef526241dce93 100644 --- a/tests/ui/const-generics/issues/issue-90318.stderr +++ b/tests/ui/const-generics/issues/issue-90318.stderr @@ -36,7 +36,7 @@ note: ...which requires evaluating type-level constant... | LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires const-evaluating + checking `consume::{constant#0}`... +note: ...which requires const-evaluating + checking `consume::::{constant#0}`... --> $DIR/issue-90318.rs:14:8 | LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, @@ -71,7 +71,7 @@ note: ...which requires evaluating type-level constant... | LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires const-evaluating + checking `test::{constant#0}`... +note: ...which requires const-evaluating + checking `test::::{constant#0}`... --> $DIR/issue-90318.rs:22:8 | LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, diff --git a/tests/ui/consts/const-size_of-cycle.stderr b/tests/ui/consts/const-size_of-cycle.stderr index 01aa5e726b451..16414017ee649 100644 --- a/tests/ui/consts/const-size_of-cycle.stderr +++ b/tests/ui/consts/const-size_of-cycle.stderr @@ -6,9 +6,9 @@ LL | bytes: [u8; std::mem::size_of::()] | note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`... --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -note: ...which requires simplifying constant for the type system `core::mem::SizedTypeProperties::SIZE`... +note: ...which requires simplifying constant for the type system `::SIZE`... --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -note: ...which requires const-evaluating + checking `core::mem::SizedTypeProperties::SIZE`... +note: ...which requires const-evaluating + checking `::SIZE`... --> $SRC_DIR/core/src/mem/mod.rs:LL:COL = note: ...which requires computing layout of `Foo`... = note: ...which requires computing layout of `[u8; std::mem::size_of::()]`... diff --git a/tests/ui/generic-const-items/recursive.stderr b/tests/ui/generic-const-items/recursive.stderr index c9a5793742899..6f9d37eb73a4d 100644 --- a/tests/ui/generic-const-items/recursive.stderr +++ b/tests/ui/generic-const-items/recursive.stderr @@ -5,7 +5,7 @@ LL | let _ = RECUR::<()>; | ^^^^^^^^^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "30"]` attribute to your crate (`recursive`) - = note: query depth increased by 17 when simplifying constant for the type system `RECUR` + = note: query depth increased by 17 when simplifying constant for the type system `RECUR::<()>` error: aborting due to 1 previous error diff --git a/tests/ui/layout/layout-cycle.stderr b/tests/ui/layout/layout-cycle.stderr index 28c35d431226e..79888b84e1df7 100644 --- a/tests/ui/layout/layout-cycle.stderr +++ b/tests/ui/layout/layout-cycle.stderr @@ -2,7 +2,7 @@ error[E0391]: cycle detected when computing layout of `S>` | = note: ...which requires computing layout of ` as Tr>::I`... = note: ...which again requires computing layout of `S>`, completing the cycle -note: cycle used when const-evaluating + checking `core::mem::SizedTypeProperties::SIZE` +note: cycle used when const-evaluating + checking `> as core::mem::SizedTypeProperties>::SIZE` --> $SRC_DIR/core/src/mem/mod.rs:LL:COL = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information diff --git a/tests/ui/offset-of/inside-array-length.stderr b/tests/ui/offset-of/inside-array-length.stderr index de110939d4aad..3ca6a2af20af2 100644 --- a/tests/ui/offset-of/inside-array-length.stderr +++ b/tests/ui/offset-of/inside-array-length.stderr @@ -33,7 +33,7 @@ error[E0391]: cycle detected when evaluating type-level constant LL | fn foo<'a, T: 'a>(_: [(); std::mem::offset_of!((T,), 0)]) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: ...which requires const-evaluating + checking `foo::{constant#0}`... +note: ...which requires const-evaluating + checking `foo::<'_, T>::{constant#0}`... --> $DIR/inside-array-length.rs:9:27 | LL | fn foo<'a, T: 'a>(_: [(); std::mem::offset_of!((T,), 0)]) {} diff --git a/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr b/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr index 1a2bc6c2c5f59..beb41901c05ef 100644 --- a/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr +++ b/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr @@ -12,7 +12,7 @@ error[E0391]: cycle detected when evaluating type-level constant LL | fn accept0(_: Container<{ T::make() }>) {} | ^^^^^^^^^^^^^ | -note: ...which requires const-evaluating + checking `accept0::{constant#0}`... +note: ...which requires const-evaluating + checking `accept0::::{constant#0}`... --> $DIR/unsatisfied-const-trait-bound.rs:28:35 | LL | fn accept0(_: Container<{ T::make() }>) {} @@ -81,13 +81,13 @@ note: ...which requires evaluating type-level constant... | LL | const fn accept1(_: Container<{ T::make() }>) {} | ^^^^^^^^^^^^^ -note: ...which requires const-evaluating + checking `accept1::{constant#0}`... +note: ...which requires const-evaluating + checking `accept1::::{constant#0}`... --> $DIR/unsatisfied-const-trait-bound.rs:32:49 | LL | const fn accept1(_: Container<{ T::make() }>) {} | ^^^^^^^^^^^^^ = note: ...which again requires checking if `accept1::{constant#0}` is a trivial const, completing the cycle -note: cycle used when const-evaluating + checking `accept1::{constant#0}` +note: cycle used when const-evaluating + checking `accept1::::{constant#0}` --> $DIR/unsatisfied-const-trait-bound.rs:32:49 | LL | const fn accept1(_: Container<{ T::make() }>) {} From 2d382871cf1da33aa1963a5c26603e7e37ce0753 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Fri, 1 May 2026 20:09:28 +0000 Subject: [PATCH 15/15] dbg --- compiler/rustc_middle/src/dep_graph/graph.rs | 37 +++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/graph.rs b/compiler/rustc_middle/src/dep_graph/graph.rs index 7b5d12791a60e..5a8e7192c5a6f 100644 --- a/compiler/rustc_middle/src/dep_graph/graph.rs +++ b/compiler/rustc_middle/src/dep_graph/graph.rs @@ -19,7 +19,6 @@ use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; use rustc_session::Session; use rustc_span::Symbol; use rustc_span::def_id::LocalDefId; -use tracing::instrument; #[cfg(debug_assertions)] use {super::debug::EdgeFilter, std::env}; @@ -739,6 +738,7 @@ impl DepGraphData { tcx.sess.used_features.lock().insert(*symbol, dep_node_index.as_u32()); } QuerySideEffect::CreateDef { parent, data } => { + tracing::trace!("SIDE-EFFECT create_def_raw({parent:?}, {data:?})"); tcx.untracked().definitions.write().create_def(*parent, *data); } } @@ -775,6 +775,10 @@ impl DepGraphData { }; let value_fingerprint = value_fingerprint.unwrap_or(Fingerprint::ZERO); + //tracing::trace!( + // "alloc_and_color_node {key:?} is {}", + // if is_green { "GREEN" } else { "RED" } + //); let dep_node_index = self.current.encoder.send_and_color( prev_index, @@ -892,19 +896,25 @@ impl DepGraphData { } /// Try to mark a dep-node which existed in the previous compilation session as green. - #[instrument(skip(self, tcx, prev_dep_node_index, frame), level = "debug")] fn try_mark_previous_green<'tcx>( &self, tcx: TyCtxt<'tcx>, prev_dep_node_index: SerializedDepNodeIndex, frame: Option<&MarkFrame<'_>>, ) -> Option { + let _span = tracing::trace_span!( + "try_mark_previous_green", + dep_node = ?self.previous.index_to_node(prev_dep_node_index), + ); + let _span = _span.enter(); + let frame = MarkFrame { index: prev_dep_node_index, parent: frame }; // We never try to mark eval_always nodes as green debug_assert!(!tcx.is_eval_always(self.previous.index_to_node(prev_dep_node_index).kind)); for parent_dep_node_index in self.previous.edge_targets_from(prev_dep_node_index) { + tracing::trace!("EXAMINE {:?}", self.previous.index_to_node(parent_dep_node_index),); match self.colors.get(parent_dep_node_index) { // This dependency has been marked as green before, we are still ok and can // continue checking the remaining dependencies. @@ -912,7 +922,14 @@ impl DepGraphData { // This dependency's result is different to the previous compilation session. We // cannot mark this dep_node as green, so stop checking. - DepNodeColor::Red => return None, + DepNodeColor::Red => { + tracing::trace!( + "RECOMPUTE {:?} BECAUSE KNOWN RED {:?}", + self.previous.index_to_node(prev_dep_node_index), + self.previous.index_to_node(parent_dep_node_index), + ); + return None; + } // We still need to determine this dependency's colour. DepNodeColor::Unknown => {} @@ -929,12 +946,24 @@ impl DepGraphData { // We failed to mark it green, so we try to force the query. if !tcx.try_force_from_dep_node(*parent_dep_node, parent_dep_node_index, &frame) { + tracing::trace!( + "RECOMPUTE {:?} BECAUSE UNFORCEABLE {:?}", + self.previous.index_to_node(prev_dep_node_index), + parent_dep_node, + ); return None; } match self.colors.get(parent_dep_node_index) { DepNodeColor::Green(_) => continue, - DepNodeColor::Red => return None, + DepNodeColor::Red => { + tracing::trace!( + "RECOMPUTE {:?} BECAUSE NEWLY RED {:?}", + self.previous.index_to_node(prev_dep_node_index), + parent_dep_node, + ); + return None; + } DepNodeColor::Unknown => {} }