From a867b8dd1cb48146d24883a26c5fd961c160d84e Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 9 Feb 2022 00:02:51 +0000 Subject: [PATCH 01/14] Add a test for issue 47384 --- src/test/run-make/issue-47384/Makefile | 12 ++++++++++++ src/test/run-make/issue-47384/lib.rs | 12 ++++++++++++ src/test/run-make/issue-47384/linker.ld | 7 +++++++ src/test/run-make/issue-47384/main.rs | 1 + 4 files changed, 32 insertions(+) create mode 100644 src/test/run-make/issue-47384/Makefile create mode 100644 src/test/run-make/issue-47384/lib.rs create mode 100644 src/test/run-make/issue-47384/linker.ld create mode 100644 src/test/run-make/issue-47384/main.rs diff --git a/src/test/run-make/issue-47384/Makefile b/src/test/run-make/issue-47384/Makefile new file mode 100644 index 0000000000000..d3d48966b8547 --- /dev/null +++ b/src/test/run-make/issue-47384/Makefile @@ -0,0 +1,12 @@ +-include ../../run-make-fulldeps/tools.mk + +# ignore-windows +# ignore-cross-compile + +all: main.rs + $(RUSTC) --crate-type lib lib.rs + $(RUSTC) --crate-type cdylib -Clink-args="-Tlinker.ld" main.rs + # Ensure `#[used]` and `KEEP`-ed section is there + objdump -s -j".static" $(TMPDIR)/libmain.so + # Ensure `#[no_mangle]` symbol is there + nm $(TMPDIR)/libmain.so | $(CGREP) bar diff --git a/src/test/run-make/issue-47384/lib.rs b/src/test/run-make/issue-47384/lib.rs new file mode 100644 index 0000000000000..99508bcdaf314 --- /dev/null +++ b/src/test/run-make/issue-47384/lib.rs @@ -0,0 +1,12 @@ +mod foo { + #[link_section = ".rodata.STATIC"] + #[used] + static STATIC: [u32; 10] = [1; 10]; +} + +mod bar { + #[no_mangle] + extern "C" fn bar() -> i32 { + 0 + } +} diff --git a/src/test/run-make/issue-47384/linker.ld b/src/test/run-make/issue-47384/linker.ld new file mode 100644 index 0000000000000..2e70acab3f496 --- /dev/null +++ b/src/test/run-make/issue-47384/linker.ld @@ -0,0 +1,7 @@ +SECTIONS +{ + .static : ALIGN(4) + { + KEEP(*(.rodata.STATIC)); + } +} diff --git a/src/test/run-make/issue-47384/main.rs b/src/test/run-make/issue-47384/main.rs new file mode 100644 index 0000000000000..02572632517ec --- /dev/null +++ b/src/test/run-make/issue-47384/main.rs @@ -0,0 +1 @@ +extern crate lib; From aa8413cd26f1eab00d781893c8e426dbc564eaf1 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 2 Apr 2022 22:27:33 +0100 Subject: [PATCH 02/14] Add `SymbolExportInfo` This is currently a wrapper to `SymbolExportLevel` but it allows later addition of extra information. --- compiler/rustc_codegen_llvm/src/back/lto.rs | 6 +- compiler/rustc_codegen_ssa/src/back/linker.rs | 8 +-- .../src/back/symbol_export.rs | 60 ++++++++++++++----- compiler/rustc_codegen_ssa/src/back/write.rs | 4 +- compiler/rustc_metadata/src/rmeta/decoder.rs | 4 +- .../src/rmeta/decoder/cstore_impl.rs | 4 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 6 +- compiler/rustc_metadata/src/rmeta/mod.rs | 4 +- .../src/middle/exported_symbols.rs | 7 +++ compiler/rustc_middle/src/query/mod.rs | 4 +- compiler/rustc_middle/src/ty/query.rs | 2 +- .../src/partitioning/default.rs | 4 +- 12 files changed, 75 insertions(+), 38 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 0f5b1c08ec2dc..6bc242b46e043 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -16,7 +16,7 @@ use rustc_errors::{FatalError, Handler}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::bug; use rustc_middle::dep_graph::WorkProduct; -use rustc_middle::middle::exported_symbols::SymbolExportLevel; +use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel}; use rustc_session::cgu_reuse_tracker::CguReuse; use rustc_session::config::{self, CrateType, Lto}; use tracing::{debug, info}; @@ -55,8 +55,8 @@ fn prepare_lto( Lto::No => panic!("didn't request LTO but we're doing LTO"), }; - let symbol_filter = &|&(ref name, level): &(String, SymbolExportLevel)| { - if level.is_below_threshold(export_threshold) { + let symbol_filter = &|&(ref name, info): &(String, SymbolExportInfo)| { + if info.level.is_below_threshold(export_threshold) { Some(CString::new(name.as_str()).unwrap()) } else { None diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 3a66bfafaf3f4..a90b8a62c623a 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -1526,8 +1526,8 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec, crate_type: CrateType) -> Vec SymbolExportLevel { } } -fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap { +fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap { assert_eq!(cnum, LOCAL_CRATE); if !tcx.sess.opts.output_types.should_codegen() { @@ -129,12 +129,17 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap< tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())), export_level ); - (def_id.to_def_id(), export_level) + (def_id.to_def_id(), SymbolExportInfo { + level: export_level, + }) }) .collect(); if let Some(id) = tcx.proc_macro_decls_static(()) { - reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C); + reachable_non_generics.insert( + id.to_def_id(), + SymbolExportInfo { level: SymbolExportLevel::C }, + ); } reachable_non_generics @@ -143,8 +148,8 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap< fn is_reachable_non_generic_provider_local(tcx: TyCtxt<'_>, def_id: DefId) -> bool { let export_threshold = threshold(tcx); - if let Some(&level) = tcx.reachable_non_generics(def_id.krate).get(&def_id) { - level.is_below_threshold(export_threshold) + if let Some(&info) = tcx.reachable_non_generics(def_id.krate).get(&def_id) { + info.level.is_below_threshold(export_threshold) } else { false } @@ -157,7 +162,7 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b fn exported_symbols_provider_local<'tcx>( tcx: TyCtxt<'tcx>, cnum: CrateNum, -) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] { +) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] { assert_eq!(cnum, LOCAL_CRATE); if !tcx.sess.opts.output_types.should_codegen() { @@ -167,13 +172,16 @@ fn exported_symbols_provider_local<'tcx>( let mut symbols: Vec<_> = tcx .reachable_non_generics(LOCAL_CRATE) .iter() - .map(|(&def_id, &level)| (ExportedSymbol::NonGeneric(def_id), level)) + .map(|(&def_id, &info)| (ExportedSymbol::NonGeneric(def_id), info)) .collect(); if tcx.entry_fn(()).is_some() { let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main")); - symbols.push((exported_symbol, SymbolExportLevel::C)); + symbols.push(( + exported_symbol, + SymbolExportInfo { level: SymbolExportLevel::C }, + )); } if tcx.allocator_kind(()).is_some() { @@ -181,7 +189,10 @@ fn exported_symbols_provider_local<'tcx>( let symbol_name = format!("__rust_{}", method.name); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name)); - symbols.push((exported_symbol, SymbolExportLevel::Rust)); + symbols.push(( + exported_symbol, + SymbolExportInfo { level: SymbolExportLevel::Rust }, + )); } } @@ -194,7 +205,10 @@ fn exported_symbols_provider_local<'tcx>( symbols.extend(PROFILER_WEAK_SYMBOLS.iter().map(|sym| { let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym)); - (exported_symbol, SymbolExportLevel::C) + ( + exported_symbol, + SymbolExportInfo { level: SymbolExportLevel::C }, + ) })); } @@ -204,7 +218,10 @@ fn exported_symbols_provider_local<'tcx>( symbols.extend(MSAN_WEAK_SYMBOLS.iter().map(|sym| { let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym)); - (exported_symbol, SymbolExportLevel::C) + ( + exported_symbol, + SymbolExportInfo { level: SymbolExportLevel::C }, + ) })); } @@ -212,7 +229,10 @@ fn exported_symbols_provider_local<'tcx>( let symbol_name = metadata_symbol_name(tcx); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name)); - symbols.push((exported_symbol, SymbolExportLevel::Rust)); + symbols.push(( + exported_symbol, + SymbolExportInfo { level: SymbolExportLevel::Rust }, + )); } if tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics() { @@ -245,7 +265,12 @@ fn exported_symbols_provider_local<'tcx>( MonoItem::Fn(Instance { def: InstanceDef::Item(def), substs }) => { if substs.non_erasable_generics().next().is_some() { let symbol = ExportedSymbol::Generic(def.did, substs); - symbols.push((symbol, SymbolExportLevel::Rust)); + symbols.push(( + symbol, + SymbolExportInfo { + level: SymbolExportLevel::Rust, + }, + )); } } MonoItem::Fn(Instance { def: InstanceDef::DropGlue(_, Some(ty)), substs }) => { @@ -254,7 +279,12 @@ fn exported_symbols_provider_local<'tcx>( substs.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)) ); - symbols.push((ExportedSymbol::DropGlue(ty), SymbolExportLevel::Rust)); + symbols.push(( + ExportedSymbol::DropGlue(ty), + SymbolExportInfo { + level: SymbolExportLevel::Rust, + }, + )); } _ => { // Any other symbols don't qualify for sharing diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index d4eaf6389dfe9..7a6e9bfd2b7c6 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -23,7 +23,7 @@ use rustc_incremental::{ }; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::exported_symbols::SymbolExportLevel; +use rustc_middle::middle::exported_symbols::SymbolExportInfo; use rustc_middle::ty::TyCtxt; use rustc_session::cgu_reuse_tracker::CguReuseTracker; use rustc_session::config::{self, CrateType, Lto, OutputFilenames, OutputType}; @@ -304,7 +304,7 @@ pub type TargetMachineFactoryFn = Arc< + Sync, >; -pub type ExportedSymbols = FxHashMap>>; +pub type ExportedSymbols = FxHashMap>>; /// Additional resources used by optimize_and_codegen (not module specific) #[derive(Clone)] diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 046322a42d85b..d7a4547bcc606 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -22,7 +22,7 @@ use rustc_hir::lang_items; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::arena::ArenaAllocatable; use rustc_middle::metadata::ModChild; -use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; +use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; use rustc_middle::middle::stability::DeprecationEntry; use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState}; use rustc_middle::thir; @@ -1405,7 +1405,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn exported_symbols( self, tcx: TyCtxt<'tcx>, - ) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] { + ) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] { tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx))) } diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index cd3a1d72d41d2..1a7c458b6a267 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -188,9 +188,9 @@ provide! { <'tcx> tcx, def_id, other, cdata, let reachable_non_generics = tcx .exported_symbols(cdata.cnum) .iter() - .filter_map(|&(exported_symbol, export_level)| { + .filter_map(|&(exported_symbol, export_info)| { if let ExportedSymbol::NonGeneric(def_id) = exported_symbol { - Some((def_id, export_level)) + Some((def_id, export_info)) } else { None } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 6c758b8e5b633..9c94dca9ecde2 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -21,7 +21,7 @@ use rustc_index::vec::Idx; use rustc_middle::hir::nested_filter; use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::exported_symbols::{ - metadata_symbol_name, ExportedSymbol, SymbolExportLevel, + metadata_symbol_name, ExportedSymbol, SymbolExportInfo, }; use rustc_middle::mir::interpret; use rustc_middle::thir; @@ -1844,8 +1844,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { // definition (as that's not defined in this crate). fn encode_exported_symbols( &mut self, - exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportLevel)], - ) -> Lazy<[(ExportedSymbol<'tcx>, SymbolExportLevel)]> { + exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportInfo)], + ) -> Lazy<[(ExportedSymbol<'tcx>, SymbolExportInfo)]> { empty_proc_macro!(self); // The metadata symbol name is special. It should not show up in // downstream crates. diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 15e8693d71282..c0b7a787b80e0 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -13,7 +13,7 @@ use rustc_hir::definitions::DefKey; use rustc_hir::lang_items; use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec}; use rustc_middle::metadata::ModChild; -use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; +use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; use rustc_middle::mir; use rustc_middle::thir; use rustc_middle::ty::fast_reject::SimplifiedType; @@ -218,7 +218,7 @@ crate struct CrateRoot<'tcx> { tables: LazyTables<'tcx>, - exported_symbols: Lazy!([(ExportedSymbol<'tcx>, SymbolExportLevel)]), + exported_symbols: Lazy!([(ExportedSymbol<'tcx>, SymbolExportInfo)]), syntax_contexts: SyntaxContextTable, expn_data: ExpnDataTable, diff --git a/compiler/rustc_middle/src/middle/exported_symbols.rs b/compiler/rustc_middle/src/middle/exported_symbols.rs index 5ea78e087f845..a605e6dfdc1d3 100644 --- a/compiler/rustc_middle/src/middle/exported_symbols.rs +++ b/compiler/rustc_middle/src/middle/exported_symbols.rs @@ -21,6 +21,13 @@ impl SymbolExportLevel { } } +/// The `SymbolExportInfo` of a symbols specifies symbol-related information +/// that is relevant to code generation and linking. +#[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] +pub struct SymbolExportInfo { + pub level: SymbolExportLevel, +} + #[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] pub enum ExportedSymbol<'tcx> { NonGeneric(DefId), diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 89761bf4e27a0..97f1d96404b5e 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1355,7 +1355,7 @@ rustc_queries! { // Does not include external symbols that don't have a corresponding DefId, // like the compiler-generated `main` function and so on. query reachable_non_generics(_: CrateNum) - -> DefIdMap { + -> DefIdMap { storage(ArenaCacheSelector<'tcx>) desc { "looking up the exported symbols of a crate" } separate_provide_extern @@ -1672,7 +1672,7 @@ rustc_queries! { /// correspond to a publicly visible symbol in `cnum` machine code. /// - The `exported_symbols` sets of different crates do not intersect. query exported_symbols(_: CrateNum) - -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] { + -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] { desc { "exported_symbols" } separate_provide_extern } diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 9e48c569c253a..6ff061a820ebf 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -3,7 +3,7 @@ use crate::infer::canonical::{self, Canonical}; use crate::lint::LintLevelMap; use crate::metadata::ModChild; use crate::middle::codegen_fn_attrs::CodegenFnAttrs; -use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; +use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; use crate::middle::lib_features::LibFeatures; use crate::middle::privacy::AccessLevels; use crate::middle::region; diff --git a/compiler/rustc_monomorphize/src/partitioning/default.rs b/compiler/rustc_monomorphize/src/partitioning/default.rs index c4ffb19f87a91..02f3efa695c34 100644 --- a/compiler/rustc_monomorphize/src/partitioning/default.rs +++ b/compiler/rustc_monomorphize/src/partitioning/default.rs @@ -5,7 +5,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::definitions::DefPathDataName; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc_middle::middle::exported_symbols::SymbolExportLevel; +use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel}; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility}; use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; use rustc_middle::ty::print::characteristic_def_id_of_type; @@ -554,7 +554,7 @@ fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibilit // C-export level items remain at `Default`, all other internal // items become `Hidden`. match tcx.reachable_non_generics(id.krate).get(&id) { - Some(SymbolExportLevel::C) => Visibility::Default, + Some(SymbolExportInfo { level: SymbolExportLevel::C, .. }) => Visibility::Default, _ => Visibility::Hidden, } } From 08b70292737b6da048ae15b3333b8b5eb1c83b67 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 2 Apr 2022 22:29:59 +0100 Subject: [PATCH 03/14] Make `#[used]` considered reachable --- compiler/rustc_passes/src/reachable.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index b520e5d04eab9..55745248c9389 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -332,6 +332,8 @@ impl CollectPrivateImplItemsVisitor<'_, '_> { // which are currently akin to allocator symbols. let codegen_attrs = self.tcx.codegen_fn_attrs(def_id); if codegen_attrs.contains_extern_indicator() + || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED) + || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) || codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) { self.worklist.push(def_id); From fefc69ab15cdeae2242a2ea4d7d09a73217a98a6 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 2 Apr 2022 22:54:51 +0100 Subject: [PATCH 04/14] Synthesis object file for `#[used]` and exported symbols --- compiler/rustc_codegen_ssa/src/back/link.rs | 69 +++++++++++++++++++ compiler/rustc_codegen_ssa/src/back/linker.rs | 46 +++++++++++++ .../rustc_codegen_ssa/src/back/metadata.rs | 2 +- .../src/back/symbol_export.rs | 54 +++++++++++++-- compiler/rustc_codegen_ssa/src/base.rs | 7 ++ compiler/rustc_codegen_ssa/src/lib.rs | 2 + .../src/middle/exported_symbols.rs | 10 +++ 7 files changed, 182 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 548ae0e411da7..a88f861311861 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -7,6 +7,7 @@ use rustc_errors::{ErrorGuaranteed, Handler}; use rustc_fs_util::fix_windows_verbatim_for_gcc; use rustc_hir::def_id::CrateNum; use rustc_middle::middle::dependency_format::Linkage; +use rustc_middle::middle::exported_symbols::SymbolExportKind; use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, LdImpl, Strip}; use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, SplitDwarfKind}; use rustc_session::cstore::DllImport; @@ -1654,6 +1655,67 @@ fn add_post_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor } } +/// Add a synthetic object file that contains reference to all symbols that we want to expose to +/// the linker. +/// +/// Background: we implement rlibs as static library (archives). Linkers treat archives +/// differently from object files: all object files participate in linking, while archives will +/// only participate in linking if they can satisfy at least one undefined reference (version +/// scripts doesn't count). This causes `#[no_mangle]` or `#[used]` items to be ignored by the +/// linker, and since they never participate in the linking, using `KEEP` in the linker scripts +/// can't keep them either. This causes #47384. +/// +/// To keep them around, we could use `--whole-archive` and equivalents to force rlib to +/// participate in linking like object files, but this proves to be expensive (#93791). Therefore +/// we instead just introduce an undefined reference to them. This could be done by `-u` command +/// line option to the linker or `EXTERN(...)` in linker scripts, however they does not only +/// introduce an undefined reference, but also make them the GC roots, preventing `--gc-sections` +/// from removing them, and this is especially problematic for embedded programming where every +/// byte counts. +/// +/// This method creates a synthetic object file, which contains undefined references to all symbols +/// that are necessary for the linking. They are only present in symbol table but not actually +/// used in any sections, so the linker will therefore pick relevant rlibs for linking, but +/// unused `#[no_mangle]` or `#[used]` can still be discard by GC sections. +fn add_linked_symbol_object( + cmd: &mut dyn Linker, + sess: &Session, + tmpdir: &Path, + symbols: &[(String, SymbolExportKind)], +) { + if symbols.is_empty() { + return; + } + + let Some(mut file) = super::metadata::create_object_file(sess) else { + return; + }; + + for (sym, kind) in symbols.iter() { + file.add_symbol(object::write::Symbol { + name: sym.clone().into(), + value: 0, + size: 0, + kind: match kind { + SymbolExportKind::Text => object::SymbolKind::Text, + SymbolExportKind::Data => object::SymbolKind::Data, + SymbolExportKind::Tls => object::SymbolKind::Tls, + }, + scope: object::SymbolScope::Unknown, + weak: false, + section: object::write::SymbolSection::Undefined, + flags: object::SymbolFlags::None, + }); + } + + let path = tmpdir.join("symbols.o"); + let result = std::fs::write(&path, file.write().unwrap()); + if let Err(e) = result { + sess.fatal(&format!("failed to write {}: {}", path.display(), e)); + } + cmd.add_object(&path); +} + /// Add object files containing code from the current crate. fn add_local_crate_regular_objects(cmd: &mut dyn Linker, codegen_results: &CodegenResults) { for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) { @@ -1797,6 +1859,13 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( // Sanitizer libraries. add_sanitizer_libraries(sess, crate_type, cmd); + add_linked_symbol_object( + cmd, + sess, + tmpdir, + &codegen_results.crate_info.linked_symbols[&crate_type], + ); + // Object code from the current crate. // Take careful note of the ordering of the arguments we pass to the linker // here. Linkers will assume that things on the left depend on things to the diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index a90b8a62c623a..044dd9556fed0 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -12,6 +12,7 @@ use std::{env, mem, str}; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_middle::middle::dependency_format::Linkage; +use rustc_middle::middle::exported_symbols::SymbolExportKind; use rustc_middle::ty::TyCtxt; use rustc_serialize::{json, Encoder}; use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip}; @@ -1557,6 +1558,51 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec, + crate_type: CrateType, +) -> Vec<(String, SymbolExportKind)> { + match crate_type { + CrateType::Executable | CrateType::Cdylib => (), + CrateType::Staticlib | CrateType::ProcMacro | CrateType::Rlib | CrateType::Dylib => { + return Vec::new(); + } + } + + let mut symbols = Vec::new(); + + let export_threshold = symbol_export::crates_export_threshold(&[crate_type]); + for &(symbol, info) in tcx.exported_symbols(LOCAL_CRATE).iter() { + if info.level.is_below_threshold(export_threshold) || info.used { + symbols.push(( + symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, LOCAL_CRATE), + info.kind, + )); + } + } + + let formats = tcx.dependency_formats(()); + let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap(); + + for (index, dep_format) in deps.iter().enumerate() { + let cnum = CrateNum::new(index + 1); + // For each dependency that we are linking to statically ... + if *dep_format == Linkage::Static { + // ... we add its symbol list to our export list. + for &(symbol, info) in tcx.exported_symbols(cnum).iter() { + if info.level.is_below_threshold(export_threshold) || info.used { + symbols.push(( + symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum), + info.kind, + )); + } + } + } + } + + symbols +} + /// Much simplified and explicit CLI for the NVPTX linker. The linker operates /// with bitcode and uses LLVM backend to generate a PTX assembly. pub struct PtxLinker<'a> { diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index c52269805c46f..2e42272805682 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -94,7 +94,7 @@ fn search_for_metadata<'a>( .map_err(|e| format!("failed to read {} section in '{}': {}", section, path.display(), e)) } -fn create_object_file(sess: &Session) -> Option> { +pub(crate) fn create_object_file(sess: &Session) -> Option> { let endianness = match sess.target.options.endian { Endian::Little => Endianness::Little, Endian::Big => Endianness::Big, diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index e14ebe3ae48f9..56159cc2e08c5 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -9,7 +9,7 @@ use rustc_hir::Node; use rustc_index::vec::IndexVec; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::exported_symbols::{ - metadata_symbol_name, ExportedSymbol, SymbolExportInfo, SymbolExportLevel, + metadata_symbol_name, ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel, }; use rustc_middle::ty::query::{ExternProviders, Providers}; use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; @@ -124,6 +124,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap< } else { symbol_export_level(tcx, def_id.to_def_id()) }; + let codegen_attrs = tcx.codegen_fn_attrs(def_id.to_def_id()); debug!( "EXPORTED SYMBOL (local): {} ({:?})", tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())), @@ -131,6 +132,17 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap< ); (def_id.to_def_id(), SymbolExportInfo { level: export_level, + kind: if tcx.is_static(def_id.to_def_id()) { + if codegen_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) { + SymbolExportKind::Tls + } else { + SymbolExportKind::Data + } + } else { + SymbolExportKind::Text + }, + used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED) + || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER), }) }) .collect(); @@ -138,7 +150,11 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap< if let Some(id) = tcx.proc_macro_decls_static(()) { reachable_non_generics.insert( id.to_def_id(), - SymbolExportInfo { level: SymbolExportLevel::C }, + SymbolExportInfo { + level: SymbolExportLevel::C, + kind: SymbolExportKind::Data, + used: false, + }, ); } @@ -180,7 +196,11 @@ fn exported_symbols_provider_local<'tcx>( symbols.push(( exported_symbol, - SymbolExportInfo { level: SymbolExportLevel::C }, + SymbolExportInfo { + level: SymbolExportLevel::C, + kind: SymbolExportKind::Text, + used: false, + }, )); } @@ -191,7 +211,11 @@ fn exported_symbols_provider_local<'tcx>( symbols.push(( exported_symbol, - SymbolExportInfo { level: SymbolExportLevel::Rust }, + SymbolExportInfo { + level: SymbolExportLevel::Rust, + kind: SymbolExportKind::Text, + used: false, + }, )); } } @@ -207,7 +231,11 @@ fn exported_symbols_provider_local<'tcx>( let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym)); ( exported_symbol, - SymbolExportInfo { level: SymbolExportLevel::C }, + SymbolExportInfo { + level: SymbolExportLevel::C, + kind: SymbolExportKind::Data, + used: false, + }, ) })); } @@ -220,7 +248,11 @@ fn exported_symbols_provider_local<'tcx>( let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym)); ( exported_symbol, - SymbolExportInfo { level: SymbolExportLevel::C }, + SymbolExportInfo { + level: SymbolExportLevel::C, + kind: SymbolExportKind::Data, + used: false, + }, ) })); } @@ -231,7 +263,11 @@ fn exported_symbols_provider_local<'tcx>( symbols.push(( exported_symbol, - SymbolExportInfo { level: SymbolExportLevel::Rust }, + SymbolExportInfo { + level: SymbolExportLevel::Rust, + kind: SymbolExportKind::Data, + used: false, + }, )); } @@ -269,6 +305,8 @@ fn exported_symbols_provider_local<'tcx>( symbol, SymbolExportInfo { level: SymbolExportLevel::Rust, + kind: SymbolExportKind::Text, + used: false, }, )); } @@ -283,6 +321,8 @@ fn exported_symbols_provider_local<'tcx>( ExportedSymbol::DropGlue(ty), SymbolExportInfo { level: SymbolExportLevel::Rust, + kind: SymbolExportKind::Text, + used: false, }, )); } diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 010560248054e..5a1d020884278 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -801,6 +801,12 @@ impl CrateInfo { .iter() .map(|&c| (c, crate::back::linker::exported_symbols(tcx, c))) .collect(); + let linked_symbols = tcx + .sess + .crate_types() + .iter() + .map(|&c| (c, crate::back::linker::linked_symbols(tcx, c))) + .collect(); let local_crate_name = tcx.crate_name(LOCAL_CRATE); let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID); let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem); @@ -834,6 +840,7 @@ impl CrateInfo { let mut info = CrateInfo { target_cpu, exported_symbols, + linked_symbols, local_crate_name, compiler_builtins: None, profiler_runtime: None, diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 6cf6be79a8628..f3d5bb4bc624a 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -28,6 +28,7 @@ use rustc_hir::def_id::CrateNum; use rustc_hir::LangItem; use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::dependency_format::Dependencies; +use rustc_middle::middle::exported_symbols::SymbolExportKind; use rustc_middle::ty::query::{ExternProviders, Providers}; use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT}; use rustc_session::cstore::{self, CrateSource}; @@ -140,6 +141,7 @@ impl From<&cstore::NativeLib> for NativeLib { pub struct CrateInfo { pub target_cpu: String, pub exported_symbols: FxHashMap>, + pub linked_symbols: FxHashMap>, pub local_crate_name: Symbol, pub compiler_builtins: Option, pub profiler_runtime: Option, diff --git a/compiler/rustc_middle/src/middle/exported_symbols.rs b/compiler/rustc_middle/src/middle/exported_symbols.rs index a605e6dfdc1d3..631fd09ec4cf6 100644 --- a/compiler/rustc_middle/src/middle/exported_symbols.rs +++ b/compiler/rustc_middle/src/middle/exported_symbols.rs @@ -21,11 +21,21 @@ impl SymbolExportLevel { } } +/// Kind of exported symbols. +#[derive(Eq, PartialEq, Debug, Copy, Clone, Encodable, Decodable, HashStable)] +pub enum SymbolExportKind { + Text, + Data, + Tls, +} + /// The `SymbolExportInfo` of a symbols specifies symbol-related information /// that is relevant to code generation and linking. #[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] pub struct SymbolExportInfo { pub level: SymbolExportLevel, + pub kind: SymbolExportKind, + pub used: bool, } #[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] From 3730fe3210c44e32fabd6ad5138fd7239a967240 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 2 Apr 2022 23:53:40 +0100 Subject: [PATCH 05/14] Ignore paths in temporary dir in reproducible build test --- src/test/run-make-fulldeps/reproducible-build/linker.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/run-make-fulldeps/reproducible-build/linker.rs b/src/test/run-make-fulldeps/reproducible-build/linker.rs index 998d1f328596c..b58614c8b4e1f 100644 --- a/src/test/run-make-fulldeps/reproducible-build/linker.rs +++ b/src/test/run-make-fulldeps/reproducible-build/linker.rs @@ -25,6 +25,12 @@ fn main() { let mut contents = Vec::new(); File::open(path).unwrap().read_to_end(&mut contents).unwrap(); + // This file is produced during linking in a temporary directory. + let arg = if arg.ends_with("/symbols.o") { + "symbols.o" + } else { + &*arg + }; out.push_str(&format!("{}: {}\n", arg, hash(&contents))); } From 460054c193e21a548cf8e0c7a86a3faf02fc96f7 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 9 Apr 2022 22:36:25 +0100 Subject: [PATCH 06/14] Add a note to reachable.rs about `#[used]` --- compiler/rustc_passes/src/reachable.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 55745248c9389..b65e334261325 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -332,9 +332,12 @@ impl CollectPrivateImplItemsVisitor<'_, '_> { // which are currently akin to allocator symbols. let codegen_attrs = self.tcx.codegen_fn_attrs(def_id); if codegen_attrs.contains_extern_indicator() + || codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) + // FIXME(nbdd0121): `#[used]` are marked as reachable here so it's picked up by + // `linked_symbols` in cg_ssa. They won't be exported in binary or cdylib due to their + // `SymbolExportLevel::Rust` export level but may end up being exported in dylibs. || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED) || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) - || codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) { self.worklist.push(def_id); } From 98cd818d785f38b59ec874e13e7b83f6521553c7 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sun, 10 Apr 2022 02:16:12 +0100 Subject: [PATCH 07/14] Refactor exported_symbols and linked_symbols for code reuse --- compiler/rustc_codegen_ssa/src/back/linker.rs | 70 +++++++------------ 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 044dd9556fed0..fce340232500f 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -12,7 +12,7 @@ use std::{env, mem, str}; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_middle::middle::dependency_format::Linkage; -use rustc_middle::middle::exported_symbols::SymbolExportKind; +use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportKind}; use rustc_middle::ty::TyCtxt; use rustc_serialize::{json, Encoder}; use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip}; @@ -1519,22 +1519,13 @@ impl<'a> L4Bender<'a> { } } -pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec { - if let Some(ref exports) = tcx.sess.target.override_export_symbols { - return exports.clone(); - } - - let mut symbols = Vec::new(); - - let export_threshold = symbol_export::crates_export_threshold(&[crate_type]); +fn for_each_exported_symbols_include_dep<'tcx>( + tcx: TyCtxt<'tcx>, + crate_type: CrateType, + mut callback: impl FnMut(ExportedSymbol<'tcx>, SymbolExportInfo, CrateNum), +) { for &(symbol, info) in tcx.exported_symbols(LOCAL_CRATE).iter() { - if info.level.is_below_threshold(export_threshold) { - symbols.push(symbol_export::symbol_name_for_instance_in_crate( - tcx, - symbol, - LOCAL_CRATE, - )); - } + callback(symbol, info, LOCAL_CRATE); } let formats = tcx.dependency_formats(()); @@ -1544,16 +1535,26 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec, crate_type: CrateType) -> Vec { + if let Some(ref exports) = tcx.sess.target.override_export_symbols { + return exports.clone(); + } + + let mut symbols = Vec::new(); + + let export_threshold = symbol_export::crates_export_threshold(&[crate_type]); + for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| { + if info.level.is_below_threshold(export_threshold) { + symbols.push(symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum)); + } + }); symbols } @@ -1572,33 +1573,14 @@ pub(crate) fn linked_symbols( let mut symbols = Vec::new(); let export_threshold = symbol_export::crates_export_threshold(&[crate_type]); - for &(symbol, info) in tcx.exported_symbols(LOCAL_CRATE).iter() { + for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| { if info.level.is_below_threshold(export_threshold) || info.used { symbols.push(( - symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, LOCAL_CRATE), + symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum), info.kind, )); } - } - - let formats = tcx.dependency_formats(()); - let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap(); - - for (index, dep_format) in deps.iter().enumerate() { - let cnum = CrateNum::new(index + 1); - // For each dependency that we are linking to statically ... - if *dep_format == Linkage::Static { - // ... we add its symbol list to our export list. - for &(symbol, info) in tcx.exported_symbols(cnum).iter() { - if info.level.is_below_threshold(export_threshold) || info.used { - symbols.push(( - symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum), - info.kind, - )); - } - } - } - } + }); symbols } From 849ede1cee9cca22683f9061f466cee82b738a36 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 13 Apr 2022 18:28:57 -0700 Subject: [PATCH 08/14] Update books --- src/doc/book | 2 +- src/doc/nomicon | 2 +- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- src/doc/rustc-dev-guide | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/doc/book b/src/doc/book index ea90bbaf53ba6..765318b844569 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit ea90bbaf53ba64ef4e2da9ac2352b298aec6bec8 +Subproject commit 765318b844569a642ceef7bf1adab9639cbf6af3 diff --git a/src/doc/nomicon b/src/doc/nomicon index 11f1165e8a2f5..c7d8467ca9158 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit 11f1165e8a2f5840467e748c8108dc53c948ee9a +Subproject commit c7d8467ca9158da58ef295ae65dbf00a308752d9 diff --git a/src/doc/reference b/src/doc/reference index c97d14fa6fed0..b5f6c2362baf9 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit c97d14fa6fed0baa9255432b8a93cb70614f80e3 +Subproject commit b5f6c2362baf932db9440fbfcb509b309237ee85 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index ec954f35eedf5..c2a98d9fc5d29 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit ec954f35eedf592cd173b21c05a7f80a65b61d8a +Subproject commit c2a98d9fc5d29c481d42052fbeccfde15ed03116 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index 155126b1d2e2c..eeb5a83c15b6a 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit 155126b1d2e2cb01ddb1d7ba9489b90d7cd173ad +Subproject commit eeb5a83c15b6ae60df3e4f19207376b22c6fbc4c From 73e354906b7c67853cc4e579191b8b52405bf8e7 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 15 Apr 2022 23:53:58 +0100 Subject: [PATCH 09/14] Fix tests --- compiler/rustc_codegen_ssa/src/back/link.rs | 6 +++--- src/test/run-make/issue-47384/Makefile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index a88f861311861..45ae5ffc5131e 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1856,9 +1856,6 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( // Pre-link CRT objects. add_pre_link_objects(cmd, sess, link_output_kind, crt_objects_fallback); - // Sanitizer libraries. - add_sanitizer_libraries(sess, crate_type, cmd); - add_linked_symbol_object( cmd, sess, @@ -1866,6 +1863,9 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( &codegen_results.crate_info.linked_symbols[&crate_type], ); + // Sanitizer libraries. + add_sanitizer_libraries(sess, crate_type, cmd); + // Object code from the current crate. // Take careful note of the ordering of the arguments we pass to the linker // here. Linkers will assume that things on the left depend on things to the diff --git a/src/test/run-make/issue-47384/Makefile b/src/test/run-make/issue-47384/Makefile index d3d48966b8547..f10365f8c8811 100644 --- a/src/test/run-make/issue-47384/Makefile +++ b/src/test/run-make/issue-47384/Makefile @@ -1,6 +1,6 @@ -include ../../run-make-fulldeps/tools.mk -# ignore-windows +# only-linux # ignore-cross-compile all: main.rs From 0db70ca26313b847738fd9405c67e9c43e9ee21b Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 10 Apr 2022 17:09:56 -0500 Subject: [PATCH 10/14] Require all paths passed to `ShouldRun::paths` to exist on disk This has two benefits: 1. There is a clearer mental model of how bootstrap works. Steps correspond to paths on disk unless it's strictly impossible for them to do so (e.g. dist components). 2. Bootstrap has better checks for internal consistency. This caught several issues: - `src/sanitizers` doesn't exist; I changed it to just be a `sanitizers` alias. - `src/tools/lld` doesn't exist; I removed it, since `lld` alone already works. - `src/llvm` doesn't exist; removed it since `llvm` and `src/llvm-project` both work. - `src/lldb_batchmode.py` doesn't exist, it was moved to `src/etc`. - `install` was still using `src/librustc` instead of `compiler/rustc`. - None of the tools in `dist` / `install` allowed using `src/tools/X` to build them. This might be intentional - I can change them to aliases if you like. --- src/bootstrap/builder.rs | 25 ++++++++++++++++++++- src/bootstrap/dist.rs | 45 +++++++++++++++++++------------------- src/bootstrap/install.rs | 28 ++++++++++++------------ src/bootstrap/native.rs | 6 ++--- src/bootstrap/test.rs | 2 +- src/bootstrap/toolstate.rs | 2 +- 6 files changed, 66 insertions(+), 42 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 8c06a0070139d..cfcc807d29387 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -364,6 +364,19 @@ impl<'a> ShouldRun<'a> { self } + // single alias, which does not correspond to any on-disk path + pub fn alias(mut self, alias: &str) -> Self { + assert!( + !self.builder.src.join(alias).exists(), + "use `builder.path()` for real paths: {}", + alias + ); + self.paths.insert(PathSet::Set( + std::iter::once(TaskPath { path: alias.into(), kind: Some(self.kind) }).collect(), + )); + self + } + // single, non-aliased path pub fn path(self, path: &str) -> Self { self.paths(&[path]) @@ -372,7 +385,17 @@ impl<'a> ShouldRun<'a> { // multiple aliases for the same job pub fn paths(mut self, paths: &[&str]) -> Self { self.paths.insert(PathSet::Set( - paths.iter().map(|p| TaskPath { path: p.into(), kind: Some(self.kind) }).collect(), + paths + .iter() + .map(|p| { + assert!( + self.builder.src.join(p).exists(), + "`should_run.paths` should correspond to real on-disk paths - use `alias` if there is no relevant path: {}", + p + ); + TaskPath { path: p.into(), kind: Some(self.kind) } + }) + .collect(), )); self } diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index fdd1581d9cd95..e3287e35227b9 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -61,7 +61,7 @@ impl Step for Docs { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = run.builder.config.docs; - run.path("rust-docs").default_condition(default) + run.alias("rust-docs").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -94,7 +94,7 @@ impl Step for RustcDocs { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let builder = run.builder; - run.path("rustc-docs").default_condition(builder.config.compiler_docs) + run.alias("rustc-docs").default_condition(builder.config.compiler_docs) } fn make_run(run: RunConfig<'_>) { @@ -272,7 +272,7 @@ impl Step for Mingw { const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rust-mingw") + run.alias("rust-mingw") } fn make_run(run: RunConfig<'_>) { @@ -313,7 +313,7 @@ impl Step for Rustc { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rustc") + run.alias("rustc") } fn make_run(run: RunConfig<'_>) { @@ -456,7 +456,7 @@ impl Step for DebuggerScripts { type Output = (); fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/lldb_batchmode.py") + run.path("src/etc/lldb_batchmode.py") } fn make_run(run: RunConfig<'_>) { @@ -547,7 +547,7 @@ impl Step for Std { const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rust-std") + run.alias("rust-std") } fn make_run(run: RunConfig<'_>) { @@ -594,7 +594,7 @@ impl Step for RustcDev { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rustc-dev") + run.alias("rustc-dev") } fn make_run(run: RunConfig<'_>) { @@ -653,7 +653,7 @@ impl Step for Analysis { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "analysis"); - run.path("rust-analysis").default_condition(default) + run.alias("rust-analysis").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -790,7 +790,7 @@ impl Step for Src { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rust-src") + run.alias("rust-src") } fn make_run(run: RunConfig<'_>) { @@ -848,7 +848,7 @@ impl Step for PlainSourceTarball { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let builder = run.builder; - run.path("rustc-src").default_condition(builder.config.rust_dist_src) + run.alias("rustc-src").default_condition(builder.config.rust_dist_src) } fn make_run(run: RunConfig<'_>) { @@ -942,7 +942,7 @@ impl Step for Cargo { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "cargo"); - run.path("cargo").default_condition(default) + run.alias("cargo").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -998,7 +998,7 @@ impl Step for Rls { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "rls"); - run.path("rls").default_condition(default) + run.alias("rls").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1045,7 +1045,7 @@ impl Step for RustAnalyzer { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "rust-analyzer"); - run.path("rust-analyzer").default_condition(default) + run.alias("rust-analyzer").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1101,7 +1101,7 @@ impl Step for Clippy { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "clippy"); - run.path("clippy").default_condition(default) + run.alias("clippy").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1152,7 +1152,7 @@ impl Step for Miri { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "miri"); - run.path("miri").default_condition(default) + run.alias("miri").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1212,7 +1212,7 @@ impl Step for Rustfmt { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "rustfmt"); - run.path("rustfmt").default_condition(default) + run.alias("rustfmt").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1271,7 +1271,7 @@ impl Step for RustDemangler { // we run the step by default when only `extended = true`, and decide whether to actually // run it or not later. let default = run.builder.config.extended; - run.path("rust-demangler").default_condition(default) + run.alias("rust-demangler").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1324,7 +1324,7 @@ impl Step for Extended { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let builder = run.builder; - run.path("extended").default_condition(builder.config.extended) + run.alias("extended").default_condition(builder.config.extended) } fn make_run(run: RunConfig<'_>) { @@ -1968,7 +1968,8 @@ impl Step for LlvmTools { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "llvm-tools"); - run.path("llvm-tools").default_condition(default) + // FIXME: allow using the names of the tools themselves? + run.alias("llvm-tools").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -2022,7 +2023,7 @@ impl Step for RustDev { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rust-dev") + run.alias("rust-dev") } fn make_run(run: RunConfig<'_>) { @@ -2098,7 +2099,7 @@ impl Step for BuildManifest { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("build-manifest") + run.alias("build-manifest") } fn make_run(run: RunConfig<'_>) { @@ -2130,7 +2131,7 @@ impl Step for ReproducibleArtifacts { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("reproducible-artifacts") + run.alias("reproducible-artifacts") } fn make_run(run: RunConfig<'_>) { diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 27b9196d9868e..08e37a1627990 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -93,7 +93,7 @@ fn prepare_dir(mut path: PathBuf) -> String { macro_rules! install { (($sel:ident, $builder:ident, $_config:ident), $($name:ident, - $path:expr, + $condition_name: ident = $path_or_alias: literal, $default_cond:expr, only_hosts: $only_hosts:expr, $run_item:block $(, $c:ident)*;)+) => { @@ -108,7 +108,7 @@ macro_rules! install { #[allow(dead_code)] fn should_build(config: &Config) -> bool { config.extended && config.tools.as_ref() - .map_or(true, |t| t.contains($path)) + .map_or(true, |t| t.contains($path_or_alias)) } } @@ -120,7 +120,7 @@ macro_rules! install { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let $_config = &run.builder.config; - run.path($path).default_condition($default_cond) + run.$condition_name($path_or_alias).default_condition($default_cond) } fn make_run(run: RunConfig<'_>) { @@ -138,11 +138,11 @@ macro_rules! install { } install!((self, builder, _config), - Docs, "src/doc", _config.docs, only_hosts: false, { + Docs, path = "src/doc", _config.docs, only_hosts: false, { let tarball = builder.ensure(dist::Docs { host: self.target }).expect("missing docs"); install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball); }; - Std, "library/std", true, only_hosts: false, { + Std, path = "library/std", true, only_hosts: false, { for target in &builder.targets { // `expect` should be safe, only None when host != build, but this // only runs when host == build @@ -153,13 +153,13 @@ install!((self, builder, _config), install_sh(builder, "std", self.compiler.stage, Some(*target), &tarball); } }; - Cargo, "cargo", Self::should_build(_config), only_hosts: true, { + Cargo, alias = "cargo", Self::should_build(_config), only_hosts: true, { let tarball = builder .ensure(dist::Cargo { compiler: self.compiler, target: self.target }) .expect("missing cargo"); install_sh(builder, "cargo", self.compiler.stage, Some(self.target), &tarball); }; - Rls, "rls", Self::should_build(_config), only_hosts: true, { + Rls, alias = "rls", Self::should_build(_config), only_hosts: true, { if let Some(tarball) = builder.ensure(dist::Rls { compiler: self.compiler, target: self.target }) { install_sh(builder, "rls", self.compiler.stage, Some(self.target), &tarball); } else { @@ -168,7 +168,7 @@ install!((self, builder, _config), ); } }; - RustAnalyzer, "rust-analyzer", Self::should_build(_config), only_hosts: true, { + RustAnalyzer, alias = "rust-analyzer", Self::should_build(_config), only_hosts: true, { if let Some(tarball) = builder.ensure(dist::RustAnalyzer { compiler: self.compiler, target: self.target }) { @@ -179,13 +179,13 @@ install!((self, builder, _config), ); } }; - Clippy, "clippy", Self::should_build(_config), only_hosts: true, { + Clippy, alias = "clippy", Self::should_build(_config), only_hosts: true, { let tarball = builder .ensure(dist::Clippy { compiler: self.compiler, target: self.target }) .expect("missing clippy"); install_sh(builder, "clippy", self.compiler.stage, Some(self.target), &tarball); }; - Miri, "miri", Self::should_build(_config), only_hosts: true, { + Miri, alias = "miri", Self::should_build(_config), only_hosts: true, { if let Some(tarball) = builder.ensure(dist::Miri { compiler: self.compiler, target: self.target }) { install_sh(builder, "miri", self.compiler.stage, Some(self.target), &tarball); } else { @@ -194,7 +194,7 @@ install!((self, builder, _config), ); } }; - Rustfmt, "rustfmt", Self::should_build(_config), only_hosts: true, { + Rustfmt, alias = "rustfmt", Self::should_build(_config), only_hosts: true, { if let Some(tarball) = builder.ensure(dist::Rustfmt { compiler: self.compiler, target: self.target @@ -206,7 +206,7 @@ install!((self, builder, _config), ); } }; - RustDemangler, "rust-demangler", Self::should_build(_config), only_hosts: true, { + RustDemangler, alias = "rust-demangler", Self::should_build(_config), only_hosts: true, { // Note: Even though `should_build` may return true for `extended` default tools, // dist::RustDemangler may still return None, unless the target-dependent `profiler` config // is also true, or the `tools` array explicitly includes "rust-demangler". @@ -222,7 +222,7 @@ install!((self, builder, _config), ); } }; - Analysis, "analysis", Self::should_build(_config), only_hosts: false, { + Analysis, alias = "analysis", Self::should_build(_config), only_hosts: false, { // `expect` should be safe, only None with host != build, but this // only uses the `build` compiler let tarball = builder.ensure(dist::Analysis { @@ -234,7 +234,7 @@ install!((self, builder, _config), }).expect("missing analysis"); install_sh(builder, "analysis", self.compiler.stage, Some(self.target), &tarball); }; - Rustc, "src/librustc", true, only_hosts: true, { + Rustc, path = "compiler/rustc", true, only_hosts: true, { let tarball = builder.ensure(dist::Rustc { compiler: builder.compiler(builder.top_stage, self.target), }); diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 6d7ca9a94cfbd..73fb2dad1e3c2 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -122,7 +122,7 @@ impl Step for Llvm { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/llvm-project").path("src/llvm-project/llvm").path("src/llvm") + run.path("src/llvm-project").path("src/llvm-project/llvm") } fn make_run(run: RunConfig<'_>) { @@ -605,7 +605,7 @@ impl Step for Lld { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/llvm-project/lld").path("src/tools/lld") + run.path("src/llvm-project/lld") } fn make_run(run: RunConfig<'_>) { @@ -771,7 +771,7 @@ impl Step for Sanitizers { type Output = Vec; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/llvm-project/compiler-rt").path("src/sanitizers") + run.alias("sanitizers") } fn make_run(run: RunConfig<'_>) { diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index b88684791bc6d..703b876f301a0 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -2295,7 +2295,7 @@ impl Step for Distcheck { type Output = (); fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("distcheck") + run.alias("distcheck") } fn make_run(run: RunConfig<'_>) { diff --git a/src/bootstrap/toolstate.rs b/src/bootstrap/toolstate.rs index c7ea254c5b1d7..3ee6a42d987a0 100644 --- a/src/bootstrap/toolstate.rs +++ b/src/bootstrap/toolstate.rs @@ -234,7 +234,7 @@ impl Step for ToolStateCheck { } fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("check-tools") + run.alias("check-tools") } fn make_run(run: RunConfig<'_>) { From 07ee0317638cf1f290a8dace1c7ccc8fea16a236 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 15 Apr 2022 19:27:53 +0200 Subject: [PATCH 11/14] Stop using CRATE_DEF_INDEX. `CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want. --- .../src/back/symbol_export.rs | 17 +----- compiler/rustc_hir/src/def.rs | 6 +-- compiler/rustc_hir/src/definitions.rs | 5 -- compiler/rustc_hir/src/hir_id.rs | 9 ++-- .../src/rmeta/decoder/cstore_impl.rs | 4 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- .../rustc_middle/src/dep_graph/dep_node.rs | 4 +- compiler/rustc_middle/src/middle/stability.rs | 5 +- compiler/rustc_middle/src/mir/mod.rs | 4 +- compiler/rustc_middle/src/ty/mod.rs | 8 +-- compiler/rustc_middle/src/ty/print/pretty.rs | 14 +++-- .../rustc_middle/src/ty/structural_impls.rs | 3 +- .../src/partitioning/default.rs | 6 +-- compiler/rustc_passes/src/entry.rs | 53 ++++++++----------- compiler/rustc_passes/src/hir_id_validator.rs | 4 +- compiler/rustc_passes/src/stability.rs | 4 +- .../rustc_query_impl/src/profiling_support.rs | 4 +- .../rustc_resolve/src/build_reduced_graph.rs | 16 +++--- compiler/rustc_resolve/src/diagnostics.rs | 4 +- compiler/rustc_resolve/src/late.rs | 4 +- .../rustc_resolve/src/late/diagnostics.rs | 10 ++-- compiler/rustc_resolve/src/lib.rs | 11 ++-- compiler/rustc_span/src/def_id.rs | 15 +++++- src/librustdoc/clean/mod.rs | 6 +-- src/librustdoc/clean/types.rs | 16 ++---- src/librustdoc/formats/cache.rs | 4 +- src/librustdoc/html/format.rs | 5 +- src/librustdoc/json/conversions.rs | 3 +- src/librustdoc/visit_lib.rs | 4 +- .../clippy/clippy_lints/src/missing_doc.rs | 6 +-- 30 files changed, 109 insertions(+), 147 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 765bd877db169..7b7c676c26cd1 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -1,12 +1,10 @@ use std::collections::hash_map::Entry::*; use rustc_ast::expand::allocator::ALLOCATOR_METHODS; -use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; -use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE}; use rustc_hir::Node; -use rustc_index::vec::IndexVec; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::exported_symbols::{ metadata_symbol_name, ExportedSymbol, SymbolExportLevel, @@ -277,17 +275,6 @@ fn upstream_monomorphizations_provider( let mut instances: DefIdMap> = Default::default(); - let cnum_stable_ids: IndexVec = { - let mut cnum_stable_ids = IndexVec::from_elem_n(Fingerprint::ZERO, cnums.len() + 1); - - for &cnum in cnums.iter() { - cnum_stable_ids[cnum] = - tcx.def_path_hash(DefId { krate: cnum, index: CRATE_DEF_INDEX }).0; - } - - cnum_stable_ids - }; - let drop_in_place_fn_def_id = tcx.lang_items().drop_in_place_fn(); for &cnum in cnums.iter() { @@ -316,7 +303,7 @@ fn upstream_monomorphizations_provider( // If there are multiple monomorphizations available, // we select one deterministically. let other_cnum = *e.get(); - if cnum_stable_ids[other_cnum] > cnum_stable_ids[cnum] { + if tcx.stable_crate_id(other_cnum) > tcx.stable_crate_id(cnum) { e.insert(cnum); } } diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 53d60d280c001..324e110005717 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -1,4 +1,4 @@ -use crate::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use crate::def_id::DefId; use crate::hir; use rustc_ast as ast; @@ -124,9 +124,7 @@ impl DefKind { pub fn descr(self, def_id: DefId) -> &'static str { match self { DefKind::Fn => "function", - DefKind::Mod if def_id.index == CRATE_DEF_INDEX && def_id.krate != LOCAL_CRATE => { - "crate" - } + DefKind::Mod if def_id.is_crate_root() && !def_id.is_local() => "crate", DefKind::Mod => "module", DefKind::Static(..) => "static", DefKind::Enum => "enum", diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index 4908992085a6e..bce9ba12ac0c4 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -353,11 +353,6 @@ impl Definitions { } } - /// Retrieves the root definition. - pub fn get_root_def(&self) -> LocalDefId { - LocalDefId { local_def_index: CRATE_DEF_INDEX } - } - /// Adds a definition with a parent definition. pub fn create_def( &mut self, diff --git a/compiler/rustc_hir/src/hir_id.rs b/compiler/rustc_hir/src/hir_id.rs index 3b5e4dcf5e011..e0ff28dff15cd 100644 --- a/compiler/rustc_hir/src/hir_id.rs +++ b/compiler/rustc_hir/src/hir_id.rs @@ -1,4 +1,4 @@ -use crate::def_id::{LocalDefId, CRATE_DEF_INDEX}; +use crate::def_id::{LocalDefId, CRATE_DEF_ID}; use std::fmt; /// Uniquely identifies a node in the HIR of the current crate. It is @@ -84,8 +84,5 @@ impl ItemLocalId { pub const INVALID: ItemLocalId = ItemLocalId::MAX; } -/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`. -pub const CRATE_HIR_ID: HirId = HirId { - owner: LocalDefId { local_def_index: CRATE_DEF_INDEX }, - local_id: ItemLocalId::from_u32(0), -}; +/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`. +pub const CRATE_HIR_ID: HirId = HirId { owner: CRATE_DEF_ID, local_id: ItemLocalId::from_u32(0) }; diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 63bf929fb8639..9c88171d17566 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -5,7 +5,7 @@ use crate::native_libs; use rustc_ast as ast; use rustc_hir::def::{CtorKind, DefKind, Res}; -use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; use rustc_middle::metadata::ModChild; use rustc_middle::middle::exported_symbols::ExportedSymbol; @@ -324,7 +324,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) { continue; } - bfs_queue.push_back(DefId { krate: cnum, index: CRATE_DEF_INDEX }); + bfs_queue.push_back(cnum.as_def_id()); } let mut add_child = |bfs_queue: &mut VecDeque<_>, child: &ModChild, parent: DefId| { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index e967750aebb52..50010fb83cf3b 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1633,7 +1633,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let hir = tcx.hir(); let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index; - let stability = tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)); + let stability = tcx.lookup_stability(CRATE_DEF_ID); let macros = self.lazy(tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index)); let spans = self.tcx.sess.parse_sess.proc_macro_quoted_spans(); diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index d20be0a34d2d5..8402ca3028cce 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -60,7 +60,7 @@ use crate::mir::mono::MonoItem; use crate::ty::TyCtxt; use rustc_data_structures::fingerprint::Fingerprint; -use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_hir::definitions::DefPathHash; use rustc_hir::HirId; use rustc_query_system::dep_graph::FingerprintStyle; @@ -366,7 +366,7 @@ impl<'tcx> DepNodeParams> for CrateNum { #[inline(always)] fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint { - let def_id = DefId { krate: *self, index: CRATE_DEF_INDEX }; + let def_id = self.as_def_id(); def_id.to_fingerprint(tcx) } diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index fd6e241346db8..758658c3d8c94 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -11,7 +11,7 @@ use rustc_errors::{Applicability, Diagnostic}; use rustc_feature::GateIssue; use rustc_hir as hir; use rustc_hir::def::DefKind; -use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self, HirId}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE}; @@ -370,8 +370,7 @@ impl<'tcx> TyCtxt<'tcx> { }; } - let is_staged_api = - self.lookup_stability(DefId { index: CRATE_DEF_INDEX, ..def_id }).is_some(); + let is_staged_api = self.lookup_stability(def_id.krate.as_def_id()).is_some(); if !is_staged_api { return EvalResult::Allow; } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 49769b7ae3d89..4f4b6cf704fa9 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -15,7 +15,7 @@ use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex} use rustc_errors::ErrorGuaranteed; use rustc_hir::def::{CtorKind, Namespace}; -use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; use rustc_hir::{self, GeneratorKind}; use rustc_hir::{self as hir, HirId}; use rustc_session::Session; @@ -385,7 +385,7 @@ impl<'tcx> Body<'tcx> { pub fn new_cfg_only(basic_blocks: IndexVec>) -> Self { let mut body = Body { phase: MirPhase::Built, - source: MirSource::item(DefId::local(CRATE_DEF_INDEX)), + source: MirSource::item(CRATE_DEF_ID.to_def_id()), basic_blocks, source_scopes: IndexVec::new(), generator: None, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index c2accea11ba2a..2901772bc74ec 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -36,7 +36,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::tagged_ptr::CopyTaggedPtr; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; -use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, CRATE_DEF_ID}; use rustc_hir::Node; use rustc_macros::HashStable; use rustc_query_system::ich::StableHashingContext; @@ -319,7 +319,7 @@ impl Visibility { pub fn from_hir(visibility: &hir::Visibility<'_>, id: hir::HirId, tcx: TyCtxt<'_>) -> Self { match visibility.node { hir::VisibilityKind::Public => Visibility::Public, - hir::VisibilityKind::Crate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)), + hir::VisibilityKind::Crate(_) => Visibility::Restricted(CRATE_DEF_ID.to_def_id()), hir::VisibilityKind::Restricted { ref path, .. } => match path.res { // If there is no resolution, `resolve` will have already reported an error, so // assume that the visibility is public to avoid reporting more privacy errors. @@ -1992,8 +1992,8 @@ impl<'tcx> TyCtxt<'tcx> { } fn opt_item_name(self, def_id: DefId) -> Option { - if def_id.index == CRATE_DEF_INDEX { - Some(self.crate_name(def_id.krate)) + if let Some(cnum) = def_id.as_crate_root() { + Some(self.crate_name(cnum)) } else { let def_key = self.def_key(def_id); match def_key.disambiguated_data.data { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 4379adb604e1f..d2c5bd1898614 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sso::SsoHashSet; use rustc_hir as hir; use rustc_hir::def::{self, CtorKind, DefKind, Namespace}; -use rustc_hir::def_id::{DefId, DefIdSet, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, DefIdSet, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData}; use rustc_hir::ItemKind; use rustc_session::config::TrimmedDefPaths; @@ -336,9 +336,7 @@ pub trait PrettyPrinter<'tcx>: // If `def_id` is a direct or injected extern crate, return the // path to the crate followed by the path to the item within the crate. - if def_id.index == CRATE_DEF_INDEX { - let cnum = def_id.krate; - + if let Some(cnum) = def_id.as_crate_root() { if cnum == LOCAL_CRATE { return Ok((self.path_crate(cnum)?, true)); } @@ -2228,11 +2226,11 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { ty::BrNamed(_, _) => br.kind, ty::BrAnon(i) => { let name = region_map[&(i + 1)]; - ty::BrNamed(DefId::local(CRATE_DEF_INDEX), name) + ty::BrNamed(CRATE_DEF_ID.to_def_id(), name) } ty::BrEnv => { let name = region_map[&0]; - ty::BrNamed(DefId::local(CRATE_DEF_INDEX), name) + ty::BrNamed(CRATE_DEF_ID.to_def_id(), name) } }; self.tcx.mk_region(ty::ReLateBound( @@ -2258,7 +2256,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { } }; do_continue(&mut self, name); - ty::BrNamed(DefId::local(CRATE_DEF_INDEX), name) + ty::BrNamed(CRATE_DEF_ID.to_def_id(), name) } }; tcx.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind })) @@ -2693,7 +2691,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N let mut seen_defs: DefIdSet = Default::default(); for &cnum in tcx.crates(()).iter() { - let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX }; + let def_id = cnum.as_def_id(); // Ignore crates that are not direct dependencies. match tcx.extern_crate(def_id) { diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 5c7910db362d2..4ef6ff1835ffd 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -10,7 +10,6 @@ use crate::ty::{self, InferConst, Lift, Term, Ty, TyCtxt}; use rustc_data_structures::functor::IdFunctor; use rustc_hir as hir; use rustc_hir::def::Namespace; -use rustc_hir::def_id::CRATE_DEF_INDEX; use rustc_index::vec::{Idx, IndexVec}; use std::fmt; @@ -71,7 +70,7 @@ impl fmt::Debug for ty::BoundRegionKind { match *self { ty::BrAnon(n) => write!(f, "BrAnon({:?})", n), ty::BrNamed(did, name) => { - if did.index == CRATE_DEF_INDEX { + if did.is_crate_root() { write!(f, "BrNamed({})", name) } else { write!(f, "BrNamed({:?}, {})", did, name) diff --git a/compiler/rustc_monomorphize/src/partitioning/default.rs b/compiler/rustc_monomorphize/src/partitioning/default.rs index c4ffb19f87a91..1677419887988 100644 --- a/compiler/rustc_monomorphize/src/partitioning/default.rs +++ b/compiler/rustc_monomorphize/src/partitioning/default.rs @@ -2,7 +2,7 @@ use std::collections::hash_map::Entry; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def::DefKind; -use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::definitions::DefPathDataName; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::exported_symbols::SymbolExportLevel; @@ -335,10 +335,10 @@ fn compute_codegen_unit_name( let mut cgu_def_id = None; // Walk backwards from the item we want to find the module for. loop { - if current_def_id.index == CRATE_DEF_INDEX { + if current_def_id.is_crate_root() { if cgu_def_id.is_none() { // If we have not found a module yet, take the crate root. - cgu_def_id = Some(DefId { krate: def_id.krate, index: CRATE_DEF_INDEX }); + cgu_def_id = Some(def_id.krate.as_def_id()); } break; } else if tcx.def_kind(current_def_id) == DefKind::Mod { diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 5a1373ad1a218..db083d0453bc0 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -1,21 +1,18 @@ use rustc_ast::entry::EntryPointType; use rustc_errors::struct_span_err; -use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{ForeignItem, ImplItem, Item, ItemKind, Node, TraitItem, CRATE_HIR_ID}; -use rustc_middle::hir::map::Map; use rustc_middle::ty::query::Providers; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{DefIdTree, TyCtxt}; use rustc_session::config::{CrateType, EntryFnType}; use rustc_session::parse::feature_err; use rustc_session::Session; use rustc_span::symbol::sym; use rustc_span::{Span, DUMMY_SP}; -struct EntryContext<'a, 'tcx> { - session: &'a Session, - - map: Map<'tcx>, +struct EntryContext<'tcx> { + tcx: TyCtxt<'tcx>, /// The function that has attribute named `main`. attr_main_fn: Option<(LocalDefId, Span)>, @@ -28,10 +25,9 @@ struct EntryContext<'a, 'tcx> { non_main_fns: Vec, } -impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> { +impl<'tcx> ItemLikeVisitor<'tcx> for EntryContext<'tcx> { fn visit_item(&mut self, item: &'tcx Item<'tcx>) { - let def_key = self.map.def_key(item.def_id); - let at_root = def_key.parent == Some(CRATE_DEF_INDEX); + let at_root = self.tcx.local_parent(item.def_id) == Some(CRATE_DEF_ID); find_item(item, self, at_root); } @@ -60,13 +56,8 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> { return None; } - let mut ctxt = EntryContext { - session: tcx.sess, - map: tcx.hir(), - attr_main_fn: None, - start_fn: None, - non_main_fns: Vec::new(), - }; + let mut ctxt = + EntryContext { tcx, attr_main_fn: None, start_fn: None, non_main_fns: Vec::new() }; tcx.hir().visit_all_item_likes(&mut ctxt); @@ -75,11 +66,11 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> { // Beware, this is duplicated in `librustc_builtin_macros/test_harness.rs` // (with `ast::Item`), so make sure to keep them in sync. -fn entry_point_type(ctxt: &EntryContext<'_, '_>, item: &Item<'_>, at_root: bool) -> EntryPointType { - let attrs = ctxt.map.attrs(item.hir_id()); - if ctxt.session.contains_name(attrs, sym::start) { +fn entry_point_type(ctxt: &EntryContext<'_>, item: &Item<'_>, at_root: bool) -> EntryPointType { + let attrs = ctxt.tcx.hir().attrs(item.hir_id()); + if ctxt.tcx.sess.contains_name(attrs, sym::start) { EntryPointType::Start - } else if ctxt.session.contains_name(attrs, sym::rustc_main) { + } else if ctxt.tcx.sess.contains_name(attrs, sym::rustc_main) { EntryPointType::MainAttr } else if item.ident.name == sym::main { if at_root { @@ -98,16 +89,16 @@ fn throw_attr_err(sess: &Session, span: Span, attr: &str) { .emit(); } -fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { +fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_>, at_root: bool) { match entry_point_type(ctxt, item, at_root) { EntryPointType::None => (), _ if !matches!(item.kind, ItemKind::Fn(..)) => { - let attrs = ctxt.map.attrs(item.hir_id()); - if let Some(attr) = ctxt.session.find_by_name(attrs, sym::start) { - throw_attr_err(&ctxt.session, attr.span, "start"); + let attrs = ctxt.tcx.hir().attrs(item.hir_id()); + if let Some(attr) = ctxt.tcx.sess.find_by_name(attrs, sym::start) { + throw_attr_err(&ctxt.tcx.sess, attr.span, "start"); } - if let Some(attr) = ctxt.session.find_by_name(attrs, sym::rustc_main) { - throw_attr_err(&ctxt.session, attr.span, "rustc_main"); + if let Some(attr) = ctxt.tcx.sess.find_by_name(attrs, sym::rustc_main) { + throw_attr_err(&ctxt.tcx.sess, attr.span, "rustc_main"); } } EntryPointType::MainNamed => (), @@ -119,7 +110,7 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { ctxt.attr_main_fn = Some((item.def_id, item.span)); } else { struct_span_err!( - ctxt.session, + ctxt.tcx.sess, item.span, E0137, "multiple functions with a `#[main]` attribute" @@ -133,7 +124,7 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { if ctxt.start_fn.is_none() { ctxt.start_fn = Some((item.def_id, item.span)); } else { - struct_span_err!(ctxt.session, item.span, E0138, "multiple `start` functions") + struct_span_err!(ctxt.tcx.sess, item.span, E0138, "multiple `start` functions") .span_label(ctxt.start_fn.unwrap().1, "previous `#[start]` function here") .span_label(item.span, "multiple `start` functions") .emit(); @@ -142,7 +133,7 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { } } -fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(DefId, EntryFnType)> { +fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId, EntryFnType)> { if let Some((def_id, _)) = visitor.start_fn { Some((def_id.to_def_id(), EntryFnType::Start)) } else if let Some((def_id, _)) = visitor.attr_main_fn { @@ -177,7 +168,7 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(De } } -fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) { +fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) { let sp = tcx.def_span(CRATE_DEF_ID); if *tcx.sess.parse_sess.reached_eof.borrow() { // There's an unclosed brace that made the parser reach `Eof`, we shouldn't complain about diff --git a/compiler/rustc_passes/src/hir_id_validator.rs b/compiler/rustc_passes/src/hir_id_validator.rs index 56755d68686e3..379a6827c8aac 100644 --- a/compiler/rustc_passes/src/hir_id_validator.rs +++ b/compiler/rustc_passes/src/hir_id_validator.rs @@ -1,7 +1,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lock; use rustc_hir as hir; -use rustc_hir::def_id::{LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::intravisit; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{HirId, ItemLocalId}; @@ -89,7 +89,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> { self.owner = Some(owner); walk(self); - if owner.local_def_index == CRATE_DEF_INDEX { + if owner == CRATE_DEF_ID { return; } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 01ba9e35c24dc..35a858cb86c3f 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -6,7 +6,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::hir_id::CRATE_HIR_ID; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{FieldDef, Generics, HirId, Item, TraitRef, Ty, TyKind, Variant}; @@ -703,7 +703,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { let Some(cnum) = self.tcx.extern_mod_stmt_cnum(item.def_id) else { return; }; - let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX }; + let def_id = cnum.as_def_id(); self.tcx.check_stability(def_id, Some(item.hir_id()), item.span, None); } diff --git a/compiler/rustc_query_impl/src/profiling_support.rs b/compiler/rustc_query_impl/src/profiling_support.rs index acccf43f06285..b20aa7b53468a 100644 --- a/compiler/rustc_query_impl/src/profiling_support.rs +++ b/compiler/rustc_query_impl/src/profiling_support.rs @@ -1,7 +1,7 @@ use measureme::{StringComponent, StringId}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::profiling::SelfProfiler; -use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE}; use rustc_hir::definitions::DefPathData; use rustc_middle::ty::{TyCtxt, WithOptConstParam}; use rustc_query_system::query::QueryCache; @@ -143,7 +143,7 @@ impl SpecIntoSelfProfilingString for CrateNum { &self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>, ) -> StringId { - builder.def_id_to_string_id(DefId { krate: *self, index: CRATE_DEF_INDEX }) + builder.def_id_to_string_id(self.as_def_id()) } } diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 54e8c03156d55..77995b60a557e 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -23,7 +23,7 @@ use rustc_errors::{struct_span_err, Applicability}; use rustc_expand::base::SyntaxExtension; use rustc_expand::expand::AstFragment; use rustc_hir::def::{self, *}; -use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; use rustc_metadata::creader::LoadedMacro; use rustc_middle::bug; use rustc_middle::metadata::ModChild; @@ -140,8 +140,8 @@ impl<'a> Resolver<'a> { let parent = def_key.parent.map(|index| { self.get_nearest_non_block_module(DefId { index, krate: def_id.krate }) }); - let name = if def_id.index == CRATE_DEF_INDEX { - self.cstore().crate_name(def_id.krate) + let name = if let Some(cnum) = def_id.as_crate_root() { + self.cstore().crate_name(cnum) } else { def_key.disambiguated_data.data.get_opt_name().expect("module without name") }; @@ -250,7 +250,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { match vis.kind { ast::VisibilityKind::Public => Ok(ty::Visibility::Public), ast::VisibilityKind::Crate(..) => { - Ok(ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))) + Ok(ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id())) } ast::VisibilityKind::Inherited => { Ok(match self.parent_scope.module.kind { @@ -759,7 +759,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { let mut ctor_vis = if vis == ty::Visibility::Public && self.r.session.contains_name(&item.attrs, sym::non_exhaustive) { - ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)) + ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()) } else { vis }; @@ -1108,7 +1108,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { root_span: span, span, module_path: Vec::new(), - vis: Cell::new(ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))), + vis: Cell::new(ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id())), used: Cell::new(false), }) }; @@ -1244,7 +1244,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { let vis = if is_macro_export { ty::Visibility::Public } else { - ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)) + ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()) }; let binding = (res, vis, span, expansion).to_name_binding(self.r.arenas); self.r.set_binding_parent_module(binding, parent_scope.module); @@ -1490,7 +1490,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> { let ctor_vis = if vis == ty::Visibility::Public && self.r.session.contains_name(&variant.attrs, sym::non_exhaustive) { - ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)) + ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()) } else { vis }; diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index f3b8c1e266c58..899980a4c0887 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -10,7 +10,7 @@ use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed use rustc_feature::BUILTIN_ATTRIBUTES; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PerNS}; -use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::PrimTy; use rustc_middle::bug; use rustc_middle::ty::DefIdTree; @@ -1167,7 +1167,7 @@ impl<'a> Resolver<'a> { } Scope::ExternPrelude => { suggestions.extend(this.extern_prelude.iter().filter_map(|(ident, _)| { - let res = Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX)); + let res = Res::Def(DefKind::Mod, CRATE_DEF_ID.to_def_id()); filter_fn(res).then_some(TypoSuggestion::typo_from_res(ident.name, res)) })); } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 763f31622bc1f..1a98dd38fc97e 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -19,7 +19,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::DiagnosticId; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, DefKind, PartialRes, PerNS}; -use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; use rustc_hir::{PrimTy, TraitCandidate}; use rustc_middle::{bug, span_bug}; use rustc_session::lint; @@ -2210,7 +2210,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { // trait to resolve. In that case, we leave the `B` // segment to be resolved by type-check. return Ok(Some(PartialRes::with_unresolved_segments( - Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX)), + Res::Def(DefKind::Mod, CRATE_DEF_ID.to_def_id()), path.len(), ))); } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 0926f24ae70ef..17a9ef4b4db83 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -19,7 +19,7 @@ use rustc_errors::{ use rustc_hir as hir; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, CtorOf, DefKind}; -use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::PrimTy; use rustc_session::parse::feature_err; use rustc_span::edition::Edition; @@ -351,7 +351,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { } }) .collect::>(); - let crate_def_id = DefId::local(CRATE_DEF_INDEX); + let crate_def_id = CRATE_DEF_ID.to_def_id(); if candidates.is_empty() && is_expected(Res::Def(DefKind::Enum, crate_def_id)) { let mut enum_candidates: Vec<_> = self .r @@ -1331,10 +1331,8 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { names.extend(extern_prelude.iter().flat_map(|(ident, _)| { self.r.crate_loader.maybe_process_path_extern(ident.name).and_then( |crate_id| { - let crate_mod = Res::Def( - DefKind::Mod, - DefId { krate: crate_id, index: CRATE_DEF_INDEX }, - ); + let crate_mod = + Res::Def(DefKind::Mod, crate_id.as_def_id()); if filter_fn(crate_mod) { Some(TypoSuggestion::typo_from_res( diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 0335c40d70d8c..5389cb19b58e4 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -37,7 +37,7 @@ use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind use rustc_hir::def::Namespace::*; use rustc_hir::def::{self, CtorOf, DefKind, PartialRes}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefPathHash, LocalDefId}; -use rustc_hir::def_id::{CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::definitions::{DefKey, DefPathData, Definitions}; use rustc_hir::TraitCandidate; use rustc_index::vec::IndexVec; @@ -755,7 +755,7 @@ impl<'a> NameBinding<'a> { NameBindingKind::Module(&ModuleData { kind: ModuleKind::Def(DefKind::Mod, def_id, _), .. - }) => def_id.index == CRATE_DEF_INDEX, + }) => def_id.is_crate_root(), _ => false, } } @@ -1207,18 +1207,17 @@ impl<'a> Resolver<'a> { ); let definitions = Definitions::new(session.local_stable_crate_id(), krate.spans.inner_span); - let root = definitions.get_root_def(); let mut visibilities = FxHashMap::default(); visibilities.insert(CRATE_DEF_ID, ty::Visibility::Public); let mut def_id_to_node_id = IndexVec::default(); - assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), root); + assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), CRATE_DEF_ID); let mut node_id_to_def_id = FxHashMap::default(); - node_id_to_def_id.insert(CRATE_NODE_ID, root); + node_id_to_def_id.insert(CRATE_NODE_ID, CRATE_DEF_ID); let mut invocation_parents = FxHashMap::default(); - invocation_parents.insert(LocalExpnId::ROOT, (root, ImplTraitContext::Existential)); + invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential)); let mut extern_prelude: FxHashMap> = session .opts diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 6d1b36796d869..d5f806308cf41 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -283,8 +283,19 @@ impl DefId { self.as_local().unwrap_or_else(|| panic!("DefId::expect_local: `{:?}` isn't local", self)) } + #[inline] + pub fn is_crate_root(self) -> bool { + self.index == CRATE_DEF_INDEX + } + + #[inline] + pub fn as_crate_root(self) -> Option { + if self.is_crate_root() { Some(self.krate) } else { None } + } + + #[inline] pub fn is_top_level_module(self) -> bool { - self.is_local() && self.index == CRATE_DEF_INDEX + self.is_local() && self.is_crate_root() } } @@ -357,7 +368,7 @@ impl LocalDefId { #[inline] pub fn is_top_level_module(self) -> bool { - self.local_def_index == CRATE_DEF_INDEX + self == CRATE_DEF_ID } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 21016afbf5f99..a070cef227252 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -15,7 +15,7 @@ use rustc_attr as attr; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; -use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData}; use rustc_middle::middle::resolve_lifetime as rl; use rustc_middle::ty::fold::TypeFolder; @@ -1975,7 +1975,7 @@ fn clean_extern_crate( // this is the ID of the `extern crate` statement let cnum = cx.tcx.extern_mod_stmt_cnum(krate.def_id).unwrap_or(LOCAL_CRATE); // this is the ID of the crate itself - let crate_def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX }; + let crate_def_id = cnum.as_def_id(); let attrs = cx.tcx.hir().attrs(krate.hir_id()); let ty_vis = cx.tcx.visibility(krate.def_id); let please_inline = ty_vis.is_public() @@ -2094,7 +2094,7 @@ fn clean_use_statement( } else { if inline_attr.is_none() { if let Res::Def(DefKind::Mod, did) = path.res { - if !did.is_local() && did.index == CRATE_DEF_INDEX { + if !did.is_local() && did.is_crate_root() { // if we're `pub use`ing an extern crate root, don't inline it unless we // were specifically asked for it denied = true; diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 4b473df155f58..e30bc6e0a97ee 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -20,7 +20,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::thin_vec::ThinVec; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; -use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::lang_items::LangItem; use rustc_hir::{BodyId, Mutability}; use rustc_index::vec::IndexVec; @@ -104,14 +104,6 @@ impl ItemId { ItemId::Primitive(_, krate) => krate, } } - - #[inline] - crate fn index(self) -> Option { - match self { - ItemId::DefId(id) => Some(id.index), - _ => None, - } - } } impl From for ItemId { @@ -160,7 +152,7 @@ impl ExternalCrate { #[inline] crate fn def_id(&self) -> DefId { - DefId { krate: self.crate_num, index: CRATE_DEF_INDEX } + self.crate_num.as_def_id() } crate fn src(&self, tcx: TyCtxt<'_>) -> FileName { @@ -217,7 +209,7 @@ impl ExternalCrate { // Failing that, see if there's an attribute specifying where to find this // external crate - let did = DefId { krate: self.crate_num, index: CRATE_DEF_INDEX }; + let did = self.crate_num.as_def_id(); tcx.get_attrs(did) .lists(sym::doc) .filter(|a| a.has_name(sym::html_root_url)) @@ -559,7 +551,7 @@ impl Item { } crate fn is_crate(&self) -> bool { - self.is_mod() && self.item_id.as_def_id().map_or(false, |did| did.index == CRATE_DEF_INDEX) + self.is_mod() && self.item_id.as_def_id().map_or(false, |did| did.is_crate_root()) } crate fn is_mod(&self) -> bool { self.type_() == ItemType::Module diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index e138e434c4e04..efd1a78a9d9a5 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -1,7 +1,7 @@ use std::mem; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{CrateNum, DefId}; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::TyCtxt; use rustc_span::{sym, Symbol}; @@ -293,7 +293,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { // A crate has a module at its root, containing all items, // which should not be indexed. The crate-item itself is // inserted later on when serializing the search-index. - if item.item_id.index().map_or(false, |idx| idx != CRATE_DEF_INDEX) { + if item.item_id.as_def_id().map_or(false, |idx| !idx.is_crate_root()) { let desc = item.doc_value().map_or_else(String::new, |x| { short_markdown_summary(x.as_str(), &item.link_names(self.cache)) }); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 55b0028180f66..6954e2363f5f0 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -18,7 +18,6 @@ use rustc_hir::def_id::DefId; use rustc_middle::ty; use rustc_middle::ty::DefIdTree; use rustc_middle::ty::TyCtxt; -use rustc_span::def_id::CRATE_DEF_INDEX; use rustc_span::{sym, Symbol}; use rustc_target::spec::abi::Abi; @@ -1312,7 +1311,7 @@ impl clean::Visibility { // visibility, so it shouldn't matter. let parent_module = find_nearest_parent_module(cx.tcx(), item_did.expect_def_id()); - if vis_did.index == CRATE_DEF_INDEX { + if vis_did.is_crate_root() { "pub(crate) ".to_owned() } else if parent_module == Some(vis_did) { // `pub(in foo)` where `foo` is the parent module @@ -1360,7 +1359,7 @@ impl clean::Visibility { // visibility, so it shouldn't matter. let parent_module = find_nearest_parent_module(tcx, item_did); - if vis_did.index == CRATE_DEF_INDEX { + if vis_did.is_crate_root() { "pub(crate) ".to_owned() } else if parent_module == Some(vis_did) { // `pub(in foo)` where `foo` is the parent module diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 0b5fb48059579..56b02cd848041 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -10,7 +10,6 @@ use std::fmt; use rustc_ast::ast; use rustc_hir::{def::CtorKind, def_id::DefId}; use rustc_middle::ty::{self, TyCtxt}; -use rustc_span::def_id::CRATE_DEF_INDEX; use rustc_span::Pos; use rustc_target::spec::abi::Abi as RustcAbi; @@ -83,7 +82,7 @@ impl JsonRenderer<'_> { match v { Public => Visibility::Public, Inherited => Visibility::Default, - Restricted(did) if did.index == CRATE_DEF_INDEX => Visibility::Crate, + Restricted(did) if did.is_crate_root() => Visibility::Crate, Restricted(did) => Visibility::Restricted { parent: from_item_id(did.into()), path: self.tcx.def_path(did).to_string_no_crate_verbose(), diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs index 5bcec779bc0e7..9723cdbe3345f 100644 --- a/src/librustdoc/visit_lib.rs +++ b/src/librustdoc/visit_lib.rs @@ -1,6 +1,6 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{CrateNum, DefId}; use rustc_middle::middle::privacy::{AccessLevel, AccessLevels}; use rustc_middle::ty::TyCtxt; @@ -29,7 +29,7 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> { } crate fn visit_lib(&mut self, cnum: CrateNum) { - let did = DefId { krate: cnum, index: CRATE_DEF_INDEX }; + let did = cnum.as_def_id(); self.update(did, Some(AccessLevel::Public)); self.visit_mod(did); } diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index fc0483a929a7a..5816a95dcebff 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -10,7 +10,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_ast::ast; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty; +use rustc_middle::ty::{self, DefIdTree}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::source_map::Span; @@ -114,8 +114,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { hir::ItemKind::Fn(..) => { // ignore main() if it.ident.name == sym::main { - let def_key = cx.tcx.hir().def_key(it.def_id); - if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) { + let at_root = cx.tcx.local_parent(it.def_id) == Some(CRATE_DEF_ID); + if at_root { return; } } From 06ec80a68fb5e9ba12423461952a462fb0ae0151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Sun, 17 Apr 2022 12:36:33 +0200 Subject: [PATCH 12/14] Fix --bless not working anymore in htmldocck --- src/etc/htmldocck.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/etc/htmldocck.py b/src/etc/htmldocck.py index df215f318239e..269b6868e29f9 100644 --- a/src/etc/htmldocck.py +++ b/src/etc/htmldocck.py @@ -423,8 +423,12 @@ def check_snapshot(snapshot_name, actual_tree, normalize_to_text): else: actual_str = flatten(actual_tree) + # Conditions: + # 1. Is --bless + # 2. Are actual and expected tree different + # 3. Are actual and expected text different if not expected_str \ - or (not normalize_to_text and + or (not normalize_to_text and \ not compare_tree(make_xml(actual_str), make_xml(expected_str), stderr)) \ or (normalize_to_text and actual_str != expected_str): From e818f45cd3f8f02801d81cd23c04f6adc1b41812 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sun, 17 Apr 2022 15:39:25 +0200 Subject: [PATCH 13/14] Use revisions instead of nll compare mode for `/self/` ui tests --- ...s_pin_lifetime_mismatch-async.base.stderr} | 6 ++-- ...pes_pin_lifetime_mismatch-async.nll.stderr | 6 ++-- ..._self_types_pin_lifetime_mismatch-async.rs | 13 ++++++-- ...f_types_pin_lifetime_mismatch.base.stderr} | 6 ++-- ...elf_types_pin_lifetime_mismatch.nll.stderr | 6 ++-- ...itrary_self_types_pin_lifetime_mismatch.rs | 16 ++++++++-- ...c.stderr => lt-ref-self-async.base.stderr} | 12 +++---- .../self/elision/lt-ref-self-async.nll.stderr | 12 +++---- src/test/ui/self/elision/lt-ref-self-async.rs | 27 ++++++++++++---- ...ef-self.stderr => lt-ref-self.base.stderr} | 12 +++---- .../ui/self/elision/lt-ref-self.nll.stderr | 12 +++---- src/test/ui/self/elision/lt-ref-self.rs | 28 ++++++++++++---- ....stderr => ref-mut-self-async.base.stderr} | 12 +++---- .../elision/ref-mut-self-async.nll.stderr | 12 +++---- .../ui/self/elision/ref-mut-self-async.rs | 27 ++++++++++++---- ...t-self.stderr => ref-mut-self.base.stderr} | 12 +++---- .../ui/self/elision/ref-mut-self.nll.stderr | 12 +++---- src/test/ui/self/elision/ref-mut-self.rs | 28 ++++++++++++---- ...tderr => ref-mut-struct-async.base.stderr} | 10 +++--- .../elision/ref-mut-struct-async.nll.stderr | 10 +++--- .../ui/self/elision/ref-mut-struct-async.rs | 23 ++++++++++--- ...ruct.stderr => ref-mut-struct.base.stderr} | 10 +++--- .../ui/self/elision/ref-mut-struct.nll.stderr | 10 +++--- src/test/ui/self/elision/ref-mut-struct.rs | 24 +++++++++++--- ...sync.stderr => ref-self-async.base.stderr} | 14 ++++---- .../ui/self/elision/ref-self-async.nll.stderr | 14 ++++---- src/test/ui/self/elision/ref-self-async.rs | 31 ++++++++++++++---- .../{ref-self.stderr => ref-self.base.stderr} | 14 ++++---- src/test/ui/self/elision/ref-self.nll.stderr | 14 ++++---- src/test/ui/self/elision/ref-self.rs | 32 +++++++++++++++---- ...nc.stderr => ref-struct-async.base.stderr} | 10 +++--- .../self/elision/ref-struct-async.nll.stderr | 10 +++--- src/test/ui/self/elision/ref-struct-async.rs | 23 ++++++++++--- ...f-struct.stderr => ref-struct.base.stderr} | 10 +++--- .../ui/self/elision/ref-struct.nll.stderr | 10 +++--- src/test/ui/self/elision/ref-struct.rs | 24 +++++++++++--- 36 files changed, 360 insertions(+), 192 deletions(-) rename src/test/ui/self/{arbitrary_self_types_pin_lifetime_mismatch-async.stderr => arbitrary_self_types_pin_lifetime_mismatch-async.base.stderr} (94%) rename src/test/ui/self/{arbitrary_self_types_pin_lifetime_mismatch.stderr => arbitrary_self_types_pin_lifetime_mismatch.base.stderr} (90%) rename src/test/ui/self/elision/{lt-ref-self-async.stderr => lt-ref-self-async.base.stderr} (92%) rename src/test/ui/self/elision/{lt-ref-self.stderr => lt-ref-self.base.stderr} (96%) rename src/test/ui/self/elision/{ref-mut-self-async.stderr => ref-mut-self-async.base.stderr} (92%) rename src/test/ui/self/elision/{ref-mut-self.stderr => ref-mut-self.base.stderr} (96%) rename src/test/ui/self/elision/{ref-mut-struct-async.stderr => ref-mut-struct-async.base.stderr} (92%) rename src/test/ui/self/elision/{ref-mut-struct.stderr => ref-mut-struct.base.stderr} (97%) rename src/test/ui/self/elision/{ref-self-async.stderr => ref-self-async.base.stderr} (92%) rename src/test/ui/self/elision/{ref-self.stderr => ref-self.base.stderr} (96%) rename src/test/ui/self/elision/{ref-struct-async.stderr => ref-struct-async.base.stderr} (92%) rename src/test/ui/self/elision/{ref-struct.stderr => ref-struct.base.stderr} (97%) diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.base.stderr similarity index 94% rename from src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.stderr rename to src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.base.stderr index 299a2d2f2d3de..7985bf266d8e8 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:8:52 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:11:52 | LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | ---- ---- ^ ...but data from `f` is returned here @@ -7,7 +7,7 @@ LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | this parameter and the return type are declared with different lifetimes... error[E0623]: lifetime mismatch - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:11:82 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:82 | LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ---- ----------------- ^ ...but data from `f` is returned here @@ -15,7 +15,7 @@ LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { ( | this parameter and the return type are declared with different lifetimes... error[E0623]: lifetime mismatch - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:17:64 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:22:64 | LL | async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } | ------ --- ^^^ ...but data from `arg` is returned here diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr index 57374b7e3bb27..8a55a7c34d77b 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:8:52 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:11:52 | LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | - - ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` @@ -8,7 +8,7 @@ LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | let's call the lifetime of this reference `'2` error: lifetime may not live long enough - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:11:75 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:75 | LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | - - ^^^^^^^^^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` @@ -17,7 +17,7 @@ LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { ( | let's call the lifetime of this reference `'2` error: lifetime may not live long enough - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:17:64 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:22:64 | LL | async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } | -- - ^^^ associated function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'a` diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.rs b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.rs index f42337d534062..c54f7963c231c 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.rs +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.rs @@ -1,4 +1,7 @@ // edition:2018 +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir use std::pin::Pin; @@ -6,15 +9,19 @@ struct Foo; impl Foo { async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } - //~^ ERROR lifetime mismatch + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ lifetime may not live long enough async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } - //~^ ERROR lifetime mismatch + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ lifetime may not live long enough } type Alias = Pin; impl Foo { - async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } //~ ERROR E0623 + async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } + //[base]~^ ERROR E0623 + //[nll]~^^ lifetime may not live long enough } fn main() {} diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.base.stderr similarity index 90% rename from src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.stderr rename to src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.base.stderr index 64a574695105a..c0e2f0bd3e900 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:6:46 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:10:46 | LL | fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | ---- ---- ^ ...but data from `f` is returned here @@ -13,7 +13,7 @@ LL | fn a<'a>(self: Pin<&'a Foo>, f: &'a Foo) -> &Foo { f } | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:8:76 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:14:76 | LL | fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ---- ----------------- ^ ...but data from `f` is returned here @@ -27,7 +27,7 @@ LL | fn c<'a>(self: Pin<&'a Self>, f: &'a Foo, g: &Foo) -> (Pin<&Foo>, &Foo) | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:13:58 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:21:58 | LL | fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } | ------ --- ^^^ ...but data from `arg` is returned here diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.nll.stderr index 92241b2fb2dc1..b06ebf7047737 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.nll.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:6:46 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:10:46 | LL | fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | - - ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` @@ -8,7 +8,7 @@ LL | fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | let's call the lifetime of this reference `'2` error: lifetime may not live long enough - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:8:69 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:14:69 | LL | fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | - - ^^^^^^^^^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` @@ -17,7 +17,7 @@ LL | fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, | let's call the lifetime of this reference `'2` error: lifetime may not live long enough - --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:13:58 + --> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:21:58 | LL | fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } | -- ---- has type `Pin<&'1 Foo>` ^^^ associated function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'a` diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.rs b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.rs index 8291e44080b37..34b08b364fb5d 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.rs +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch.rs @@ -1,16 +1,26 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + use std::pin::Pin; struct Foo; impl Foo { - fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } //~ ERROR E0623 + fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } + //[base]~^ ERROR E0623 + //[nll]~^^ lifetime may not live long enough - fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } //~ ERROR E0623 + fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } + //[base]~^ ERROR E0623 + //[nll]~^^ lifetime may not live long enough } type Alias = Pin; impl Foo { - fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } //~ ERROR E0623 + fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } + //[base]~^ ERROR E0623 + //[nll]~^^ lifetime may not live long enough } fn main() {} diff --git a/src/test/ui/self/elision/lt-ref-self-async.stderr b/src/test/ui/self/elision/lt-ref-self-async.base.stderr similarity index 92% rename from src/test/ui/self/elision/lt-ref-self-async.stderr rename to src/test/ui/self/elision/lt-ref-self-async.base.stderr index 7448e8484b47a..b43854906149a 100644 --- a/src/test/ui/self/elision/lt-ref-self-async.stderr +++ b/src/test/ui/self/elision/lt-ref-self-async.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self-async.rs:13:9 + --> $DIR/lt-ref-self-async.rs:16:9 | LL | async fn ref_self(&self, f: &u32) -> &u32 { | ---- ---- @@ -9,7 +9,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self-async.rs:19:9 + --> $DIR/lt-ref-self-async.rs:24:9 | LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 { | ---- ---- @@ -19,7 +19,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self-async.rs:23:9 + --> $DIR/lt-ref-self-async.rs:30:9 | LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { | ---- ---- @@ -29,7 +29,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self-async.rs:27:9 + --> $DIR/lt-ref-self-async.rs:36:9 | LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { | ---- ---- @@ -39,7 +39,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self-async.rs:31:9 + --> $DIR/lt-ref-self-async.rs:42:9 | LL | async fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -49,7 +49,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self-async.rs:35:9 + --> $DIR/lt-ref-self-async.rs:48:9 | LL | async fn box_pin_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- diff --git a/src/test/ui/self/elision/lt-ref-self-async.nll.stderr b/src/test/ui/self/elision/lt-ref-self-async.nll.stderr index c10b8824e6d63..2ba9a6596f62d 100644 --- a/src/test/ui/self/elision/lt-ref-self-async.nll.stderr +++ b/src/test/ui/self/elision/lt-ref-self-async.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/lt-ref-self-async.rs:13:9 + --> $DIR/lt-ref-self-async.rs:16:9 | LL | async fn ref_self(&self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -9,7 +9,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/lt-ref-self-async.rs:19:9 + --> $DIR/lt-ref-self-async.rs:24:9 | LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -19,7 +19,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/lt-ref-self-async.rs:23:9 + --> $DIR/lt-ref-self-async.rs:30:9 | LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -29,7 +29,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/lt-ref-self-async.rs:27:9 + --> $DIR/lt-ref-self-async.rs:36:9 | LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -39,7 +39,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/lt-ref-self-async.rs:31:9 + --> $DIR/lt-ref-self-async.rs:42:9 | LL | async fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -49,7 +49,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/lt-ref-self-async.rs:35:9 + --> $DIR/lt-ref-self-async.rs:48:9 | LL | async fn box_pin_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/self/elision/lt-ref-self-async.rs b/src/test/ui/self/elision/lt-ref-self-async.rs index ef6cbe7772c27..24482b3a2787b 100644 --- a/src/test/ui/self/elision/lt-ref-self-async.rs +++ b/src/test/ui/self/elision/lt-ref-self-async.rs @@ -1,4 +1,7 @@ // edition:2018 +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir #![allow(non_snake_case)] @@ -10,29 +13,41 @@ impl<'a> Struct<'a> { // Test using `&self` sugar: async fn ref_self(&self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } // Test using `&Self` explicitly: async fn ref_Self(self: &Self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_pin_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } } diff --git a/src/test/ui/self/elision/lt-ref-self.stderr b/src/test/ui/self/elision/lt-ref-self.base.stderr similarity index 96% rename from src/test/ui/self/elision/lt-ref-self.stderr rename to src/test/ui/self/elision/lt-ref-self.base.stderr index 5764ab03c5519..0f5cd6fb85396 100644 --- a/src/test/ui/self/elision/lt-ref-self.stderr +++ b/src/test/ui/self/elision/lt-ref-self.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self.rs:11:9 + --> $DIR/lt-ref-self.rs:15:9 | LL | fn ref_self(&self, f: &u32) -> &u32 { | ---- ---- @@ -15,7 +15,7 @@ LL | fn ref_self<'a>(&'a self, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self.rs:17:9 + --> $DIR/lt-ref-self.rs:23:9 | LL | fn ref_Self(self: &Self, f: &u32) -> &u32 { | ---- ---- @@ -31,7 +31,7 @@ LL | fn ref_Self<'a>(self: &'a Self, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self.rs:21:9 + --> $DIR/lt-ref-self.rs:29:9 | LL | fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { | ---- ---- @@ -47,7 +47,7 @@ LL | fn box_ref_Self<'a>(self: Box<&'a Self>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self.rs:25:9 + --> $DIR/lt-ref-self.rs:35:9 | LL | fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { | ---- ---- @@ -63,7 +63,7 @@ LL | fn pin_ref_Self<'a>(self: Pin<&'a Self>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self.rs:29:9 + --> $DIR/lt-ref-self.rs:41:9 | LL | fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -79,7 +79,7 @@ LL | fn box_box_ref_Self<'a>(self: Box>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/lt-ref-self.rs:33:9 + --> $DIR/lt-ref-self.rs:47:9 | LL | fn box_pin_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- diff --git a/src/test/ui/self/elision/lt-ref-self.nll.stderr b/src/test/ui/self/elision/lt-ref-self.nll.stderr index e2de743b8f63e..1934207527b9c 100644 --- a/src/test/ui/self/elision/lt-ref-self.nll.stderr +++ b/src/test/ui/self/elision/lt-ref-self.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/lt-ref-self.rs:11:9 + --> $DIR/lt-ref-self.rs:15:9 | LL | fn ref_self(&self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -9,7 +9,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/lt-ref-self.rs:17:9 + --> $DIR/lt-ref-self.rs:23:9 | LL | fn ref_Self(self: &Self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -19,7 +19,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/lt-ref-self.rs:21:9 + --> $DIR/lt-ref-self.rs:29:9 | LL | fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -29,7 +29,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/lt-ref-self.rs:25:9 + --> $DIR/lt-ref-self.rs:35:9 | LL | fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -39,7 +39,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/lt-ref-self.rs:29:9 + --> $DIR/lt-ref-self.rs:41:9 | LL | fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -49,7 +49,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/lt-ref-self.rs:33:9 + --> $DIR/lt-ref-self.rs:47:9 | LL | fn box_pin_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/self/elision/lt-ref-self.rs b/src/test/ui/self/elision/lt-ref-self.rs index 423c7d5822df7..62bdb13dc0f95 100644 --- a/src/test/ui/self/elision/lt-ref-self.rs +++ b/src/test/ui/self/elision/lt-ref-self.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + #![allow(non_snake_case)] use std::pin::Pin; @@ -8,29 +12,41 @@ impl<'a> Struct<'a> { // Test using `&self` sugar: fn ref_self(&self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } // Test using `&Self` explicitly: fn ref_Self(self: &Self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_pin_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } } diff --git a/src/test/ui/self/elision/ref-mut-self-async.stderr b/src/test/ui/self/elision/ref-mut-self-async.base.stderr similarity index 92% rename from src/test/ui/self/elision/ref-mut-self-async.stderr rename to src/test/ui/self/elision/ref-mut-self-async.base.stderr index 6056cc46d3d8a..851337552c9ad 100644 --- a/src/test/ui/self/elision/ref-mut-self-async.stderr +++ b/src/test/ui/self/elision/ref-mut-self-async.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self-async.rs:13:9 + --> $DIR/ref-mut-self-async.rs:16:9 | LL | async fn ref_self(&mut self, f: &u32) -> &u32 { | ---- ---- @@ -9,7 +9,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self-async.rs:19:9 + --> $DIR/ref-mut-self-async.rs:24:9 | LL | async fn ref_Self(self: &mut Self, f: &u32) -> &u32 { | ---- ---- @@ -19,7 +19,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self-async.rs:23:9 + --> $DIR/ref-mut-self-async.rs:30:9 | LL | async fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 { | ---- ---- @@ -29,7 +29,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self-async.rs:27:9 + --> $DIR/ref-mut-self-async.rs:36:9 | LL | async fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 { | ---- ---- @@ -39,7 +39,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self-async.rs:31:9 + --> $DIR/ref-mut-self-async.rs:42:9 | LL | async fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -49,7 +49,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self-async.rs:35:9 + --> $DIR/ref-mut-self-async.rs:48:9 | LL | async fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- diff --git a/src/test/ui/self/elision/ref-mut-self-async.nll.stderr b/src/test/ui/self/elision/ref-mut-self-async.nll.stderr index 19496a5ef6d32..cdd464039cda0 100644 --- a/src/test/ui/self/elision/ref-mut-self-async.nll.stderr +++ b/src/test/ui/self/elision/ref-mut-self-async.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/ref-mut-self-async.rs:13:9 + --> $DIR/ref-mut-self-async.rs:16:9 | LL | async fn ref_self(&mut self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -9,7 +9,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-self-async.rs:19:9 + --> $DIR/ref-mut-self-async.rs:24:9 | LL | async fn ref_Self(self: &mut Self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -19,7 +19,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-self-async.rs:23:9 + --> $DIR/ref-mut-self-async.rs:30:9 | LL | async fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -29,7 +29,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-self-async.rs:27:9 + --> $DIR/ref-mut-self-async.rs:36:9 | LL | async fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -39,7 +39,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-self-async.rs:31:9 + --> $DIR/ref-mut-self-async.rs:42:9 | LL | async fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -49,7 +49,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-self-async.rs:35:9 + --> $DIR/ref-mut-self-async.rs:48:9 | LL | async fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/self/elision/ref-mut-self-async.rs b/src/test/ui/self/elision/ref-mut-self-async.rs index 1e65605036d6f..59b41f364f9a1 100644 --- a/src/test/ui/self/elision/ref-mut-self-async.rs +++ b/src/test/ui/self/elision/ref-mut-self-async.rs @@ -1,4 +1,7 @@ // edition:2018 +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir #![allow(non_snake_case)] @@ -10,29 +13,41 @@ impl Struct { // Test using `&mut self` sugar: async fn ref_self(&mut self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } // Test using `&mut Self` explicitly: async fn ref_Self(self: &mut Self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } } diff --git a/src/test/ui/self/elision/ref-mut-self.stderr b/src/test/ui/self/elision/ref-mut-self.base.stderr similarity index 96% rename from src/test/ui/self/elision/ref-mut-self.stderr rename to src/test/ui/self/elision/ref-mut-self.base.stderr index 416719a08e033..fceddddf20ea5 100644 --- a/src/test/ui/self/elision/ref-mut-self.stderr +++ b/src/test/ui/self/elision/ref-mut-self.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self.rs:11:9 + --> $DIR/ref-mut-self.rs:15:9 | LL | fn ref_self(&mut self, f: &u32) -> &u32 { | ---- ---- @@ -15,7 +15,7 @@ LL | fn ref_self<'a>(&'a mut self, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self.rs:17:9 + --> $DIR/ref-mut-self.rs:23:9 | LL | fn ref_Self(self: &mut Self, f: &u32) -> &u32 { | ---- ---- @@ -31,7 +31,7 @@ LL | fn ref_Self<'a>(self: &'a mut Self, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self.rs:21:9 + --> $DIR/ref-mut-self.rs:29:9 | LL | fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 { | ---- ---- @@ -47,7 +47,7 @@ LL | fn box_ref_Self<'a>(self: Box<&'a mut Self>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self.rs:25:9 + --> $DIR/ref-mut-self.rs:35:9 | LL | fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 { | ---- ---- @@ -63,7 +63,7 @@ LL | fn pin_ref_Self<'a>(self: Pin<&'a mut Self>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self.rs:29:9 + --> $DIR/ref-mut-self.rs:41:9 | LL | fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -79,7 +79,7 @@ LL | fn box_box_ref_Self<'a>(self: Box>, f: &'a u32) -> &u | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-self.rs:33:9 + --> $DIR/ref-mut-self.rs:47:9 | LL | fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- diff --git a/src/test/ui/self/elision/ref-mut-self.nll.stderr b/src/test/ui/self/elision/ref-mut-self.nll.stderr index 94bfc5f4a8186..f1f4d341b2bd8 100644 --- a/src/test/ui/self/elision/ref-mut-self.nll.stderr +++ b/src/test/ui/self/elision/ref-mut-self.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/ref-mut-self.rs:11:9 + --> $DIR/ref-mut-self.rs:15:9 | LL | fn ref_self(&mut self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -9,7 +9,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-self.rs:17:9 + --> $DIR/ref-mut-self.rs:23:9 | LL | fn ref_Self(self: &mut Self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -19,7 +19,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-self.rs:21:9 + --> $DIR/ref-mut-self.rs:29:9 | LL | fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -29,7 +29,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-self.rs:25:9 + --> $DIR/ref-mut-self.rs:35:9 | LL | fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -39,7 +39,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-self.rs:29:9 + --> $DIR/ref-mut-self.rs:41:9 | LL | fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -49,7 +49,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-self.rs:33:9 + --> $DIR/ref-mut-self.rs:47:9 | LL | fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/self/elision/ref-mut-self.rs b/src/test/ui/self/elision/ref-mut-self.rs index 8d9359dbd94b5..81bd279129d2b 100644 --- a/src/test/ui/self/elision/ref-mut-self.rs +++ b/src/test/ui/self/elision/ref-mut-self.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + #![allow(non_snake_case)] use std::pin::Pin; @@ -8,29 +12,41 @@ impl Struct { // Test using `&mut self` sugar: fn ref_self(&mut self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } // Test using `&mut Self` explicitly: fn ref_Self(self: &mut Self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } } diff --git a/src/test/ui/self/elision/ref-mut-struct-async.stderr b/src/test/ui/self/elision/ref-mut-struct-async.base.stderr similarity index 92% rename from src/test/ui/self/elision/ref-mut-struct-async.stderr rename to src/test/ui/self/elision/ref-mut-struct-async.base.stderr index 61034ae4d47b6..0de11c248758f 100644 --- a/src/test/ui/self/elision/ref-mut-struct-async.stderr +++ b/src/test/ui/self/elision/ref-mut-struct-async.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-struct-async.rs:13:9 + --> $DIR/ref-mut-struct-async.rs:16:9 | LL | async fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 { | ---- ---- @@ -9,7 +9,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-mut-struct-async.rs:17:9 + --> $DIR/ref-mut-struct-async.rs:22:9 | LL | async fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 { | ---- ---- @@ -19,7 +19,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-mut-struct-async.rs:21:9 + --> $DIR/ref-mut-struct-async.rs:28:9 | LL | async fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 { | ---- ---- @@ -29,7 +29,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-mut-struct-async.rs:25:9 + --> $DIR/ref-mut-struct-async.rs:34:9 | LL | async fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -39,7 +39,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-mut-struct-async.rs:29:9 + --> $DIR/ref-mut-struct-async.rs:40:9 | LL | async fn box_pin_ref_Struct(self: Box>, f: &u32) -> &u32 { | ---- ---- diff --git a/src/test/ui/self/elision/ref-mut-struct-async.nll.stderr b/src/test/ui/self/elision/ref-mut-struct-async.nll.stderr index 94671c7c87a5e..0ef410c8df1eb 100644 --- a/src/test/ui/self/elision/ref-mut-struct-async.nll.stderr +++ b/src/test/ui/self/elision/ref-mut-struct-async.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/ref-mut-struct-async.rs:13:9 + --> $DIR/ref-mut-struct-async.rs:16:9 | LL | async fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -9,7 +9,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-struct-async.rs:17:9 + --> $DIR/ref-mut-struct-async.rs:22:9 | LL | async fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -19,7 +19,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-struct-async.rs:21:9 + --> $DIR/ref-mut-struct-async.rs:28:9 | LL | async fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -29,7 +29,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-struct-async.rs:25:9 + --> $DIR/ref-mut-struct-async.rs:34:9 | LL | async fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -39,7 +39,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-struct-async.rs:29:9 + --> $DIR/ref-mut-struct-async.rs:40:9 | LL | async fn box_pin_ref_Struct(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/self/elision/ref-mut-struct-async.rs b/src/test/ui/self/elision/ref-mut-struct-async.rs index 990f485907f8e..7448988355c9e 100644 --- a/src/test/ui/self/elision/ref-mut-struct-async.rs +++ b/src/test/ui/self/elision/ref-mut-struct-async.rs @@ -1,4 +1,7 @@ // edition:2018 +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir #![allow(non_snake_case)] @@ -10,23 +13,33 @@ impl Struct { // Test using `&mut Struct` explicitly: async fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_pin_ref_Struct(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } } diff --git a/src/test/ui/self/elision/ref-mut-struct.stderr b/src/test/ui/self/elision/ref-mut-struct.base.stderr similarity index 97% rename from src/test/ui/self/elision/ref-mut-struct.stderr rename to src/test/ui/self/elision/ref-mut-struct.base.stderr index 6ca9ab1b2c775..a01492f6cd3fa 100644 --- a/src/test/ui/self/elision/ref-mut-struct.stderr +++ b/src/test/ui/self/elision/ref-mut-struct.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-struct.rs:11:9 + --> $DIR/ref-mut-struct.rs:15:9 | LL | fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 { | ---- ---- @@ -15,7 +15,7 @@ LL | fn ref_Struct<'a>(self: &'a mut Struct, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-struct.rs:15:9 + --> $DIR/ref-mut-struct.rs:21:9 | LL | fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 { | ---- ---- @@ -31,7 +31,7 @@ LL | fn box_ref_Struct<'a>(self: Box<&'a mut Struct>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-struct.rs:19:9 + --> $DIR/ref-mut-struct.rs:27:9 | LL | fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 { | ---- ---- @@ -47,7 +47,7 @@ LL | fn pin_ref_Struct<'a>(self: Pin<&'a mut Struct>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-struct.rs:23:9 + --> $DIR/ref-mut-struct.rs:33:9 | LL | fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -63,7 +63,7 @@ LL | fn box_box_ref_Struct<'a>(self: Box>, f: &'a u32) - | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-mut-struct.rs:27:9 + --> $DIR/ref-mut-struct.rs:39:9 | LL | fn box_pin_ref_Struct(self: Box>, f: &u32) -> &u32 { | ---- ---- diff --git a/src/test/ui/self/elision/ref-mut-struct.nll.stderr b/src/test/ui/self/elision/ref-mut-struct.nll.stderr index c9e7479ea5dff..de7eb02d7a7fe 100644 --- a/src/test/ui/self/elision/ref-mut-struct.nll.stderr +++ b/src/test/ui/self/elision/ref-mut-struct.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/ref-mut-struct.rs:11:9 + --> $DIR/ref-mut-struct.rs:15:9 | LL | fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -9,7 +9,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-struct.rs:15:9 + --> $DIR/ref-mut-struct.rs:21:9 | LL | fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -19,7 +19,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-struct.rs:19:9 + --> $DIR/ref-mut-struct.rs:27:9 | LL | fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -29,7 +29,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-struct.rs:23:9 + --> $DIR/ref-mut-struct.rs:33:9 | LL | fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -39,7 +39,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-mut-struct.rs:27:9 + --> $DIR/ref-mut-struct.rs:39:9 | LL | fn box_pin_ref_Struct(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/self/elision/ref-mut-struct.rs b/src/test/ui/self/elision/ref-mut-struct.rs index 05e275b19e4c4..72674bd65b66a 100644 --- a/src/test/ui/self/elision/ref-mut-struct.rs +++ b/src/test/ui/self/elision/ref-mut-struct.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + #![allow(non_snake_case)] use std::pin::Pin; @@ -8,23 +12,33 @@ impl Struct { // Test using `&mut Struct` explicitly: fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_pin_ref_Struct(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } } diff --git a/src/test/ui/self/elision/ref-self-async.stderr b/src/test/ui/self/elision/ref-self-async.base.stderr similarity index 92% rename from src/test/ui/self/elision/ref-self-async.stderr rename to src/test/ui/self/elision/ref-self-async.base.stderr index 0eab16e685d4c..fa13b69bb21a3 100644 --- a/src/test/ui/self/elision/ref-self-async.stderr +++ b/src/test/ui/self/elision/ref-self-async.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/ref-self-async.rs:23:9 + --> $DIR/ref-self-async.rs:26:9 | LL | async fn ref_self(&self, f: &u32) -> &u32 { | ---- ---- @@ -9,7 +9,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-self-async.rs:29:9 + --> $DIR/ref-self-async.rs:34:9 | LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 { | ---- ---- @@ -19,7 +19,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-self-async.rs:33:9 + --> $DIR/ref-self-async.rs:40:9 | LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { | ---- ---- @@ -29,7 +29,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-self-async.rs:37:9 + --> $DIR/ref-self-async.rs:46:9 | LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { | ---- ---- @@ -39,7 +39,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-self-async.rs:41:9 + --> $DIR/ref-self-async.rs:52:9 | LL | async fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -49,7 +49,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-self-async.rs:45:9 + --> $DIR/ref-self-async.rs:58:9 | LL | async fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -59,7 +59,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-self-async.rs:49:9 + --> $DIR/ref-self-async.rs:64:9 | LL | async fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 { | --- --- diff --git a/src/test/ui/self/elision/ref-self-async.nll.stderr b/src/test/ui/self/elision/ref-self-async.nll.stderr index bd1f80811b542..77faaa866505f 100644 --- a/src/test/ui/self/elision/ref-self-async.nll.stderr +++ b/src/test/ui/self/elision/ref-self-async.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/ref-self-async.rs:23:9 + --> $DIR/ref-self-async.rs:26:9 | LL | async fn ref_self(&self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -9,7 +9,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self-async.rs:29:9 + --> $DIR/ref-self-async.rs:34:9 | LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -19,7 +19,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self-async.rs:33:9 + --> $DIR/ref-self-async.rs:40:9 | LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -29,7 +29,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self-async.rs:37:9 + --> $DIR/ref-self-async.rs:46:9 | LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -39,7 +39,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self-async.rs:41:9 + --> $DIR/ref-self-async.rs:52:9 | LL | async fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -49,7 +49,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self-async.rs:45:9 + --> $DIR/ref-self-async.rs:58:9 | LL | async fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -59,7 +59,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self-async.rs:49:9 + --> $DIR/ref-self-async.rs:64:9 | LL | async fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 { | - - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/self/elision/ref-self-async.rs b/src/test/ui/self/elision/ref-self-async.rs index 0fbbd95c975d6..afe5fe100e36c 100644 --- a/src/test/ui/self/elision/ref-self-async.rs +++ b/src/test/ui/self/elision/ref-self-async.rs @@ -1,4 +1,7 @@ // edition:2018 +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir #![allow(non_snake_case)] #![feature(arbitrary_self_types)] @@ -20,33 +23,47 @@ impl Struct { // Test using `&self` sugar: async fn ref_self(&self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } // Test using `&Self` explicitly: async fn ref_Self(self: &Self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } } diff --git a/src/test/ui/self/elision/ref-self.stderr b/src/test/ui/self/elision/ref-self.base.stderr similarity index 96% rename from src/test/ui/self/elision/ref-self.stderr rename to src/test/ui/self/elision/ref-self.base.stderr index 955222f765599..8bd194d701f2f 100644 --- a/src/test/ui/self/elision/ref-self.stderr +++ b/src/test/ui/self/elision/ref-self.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/ref-self.rs:21:9 + --> $DIR/ref-self.rs:25:9 | LL | fn ref_self(&self, f: &u32) -> &u32 { | ---- ---- @@ -15,7 +15,7 @@ LL | fn ref_self<'a>(&'a self, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-self.rs:27:9 + --> $DIR/ref-self.rs:33:9 | LL | fn ref_Self(self: &Self, f: &u32) -> &u32 { | ---- ---- @@ -31,7 +31,7 @@ LL | fn ref_Self<'a>(self: &'a Self, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-self.rs:31:9 + --> $DIR/ref-self.rs:39:9 | LL | fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { | ---- ---- @@ -47,7 +47,7 @@ LL | fn box_ref_Self<'a>(self: Box<&'a Self>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-self.rs:35:9 + --> $DIR/ref-self.rs:45:9 | LL | fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { | ---- ---- @@ -63,7 +63,7 @@ LL | fn pin_ref_Self<'a>(self: Pin<&'a Self>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-self.rs:39:9 + --> $DIR/ref-self.rs:51:9 | LL | fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -79,7 +79,7 @@ LL | fn box_box_ref_Self<'a>(self: Box>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-self.rs:43:9 + --> $DIR/ref-self.rs:57:9 | LL | fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -95,7 +95,7 @@ LL | fn box_pin_ref_Self<'a>(self: Box>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-self.rs:47:9 + --> $DIR/ref-self.rs:63:9 | LL | fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 { | --- --- diff --git a/src/test/ui/self/elision/ref-self.nll.stderr b/src/test/ui/self/elision/ref-self.nll.stderr index d1fd209102e69..f2b7b0ad01957 100644 --- a/src/test/ui/self/elision/ref-self.nll.stderr +++ b/src/test/ui/self/elision/ref-self.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/ref-self.rs:21:9 + --> $DIR/ref-self.rs:25:9 | LL | fn ref_self(&self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -9,7 +9,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self.rs:27:9 + --> $DIR/ref-self.rs:33:9 | LL | fn ref_Self(self: &Self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -19,7 +19,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self.rs:31:9 + --> $DIR/ref-self.rs:39:9 | LL | fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -29,7 +29,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self.rs:35:9 + --> $DIR/ref-self.rs:45:9 | LL | fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -39,7 +39,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self.rs:39:9 + --> $DIR/ref-self.rs:51:9 | LL | fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -49,7 +49,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self.rs:43:9 + --> $DIR/ref-self.rs:57:9 | LL | fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -59,7 +59,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-self.rs:47:9 + --> $DIR/ref-self.rs:63:9 | LL | fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 { | - - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/self/elision/ref-self.rs b/src/test/ui/self/elision/ref-self.rs index e389d8518ada4..34df3da4505e8 100644 --- a/src/test/ui/self/elision/ref-self.rs +++ b/src/test/ui/self/elision/ref-self.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + #![feature(arbitrary_self_types)] #![allow(non_snake_case)] @@ -18,33 +22,47 @@ impl Struct { // Test using `&self` sugar: fn ref_self(&self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } // Test using `&Self` explicitly: fn ref_Self(self: &Self, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_box_ref_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_pin_ref_Self(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } } diff --git a/src/test/ui/self/elision/ref-struct-async.stderr b/src/test/ui/self/elision/ref-struct-async.base.stderr similarity index 92% rename from src/test/ui/self/elision/ref-struct-async.stderr rename to src/test/ui/self/elision/ref-struct-async.base.stderr index aa1d7453e83e1..8da673d44354e 100644 --- a/src/test/ui/self/elision/ref-struct-async.stderr +++ b/src/test/ui/self/elision/ref-struct-async.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/ref-struct-async.rs:13:9 + --> $DIR/ref-struct-async.rs:16:9 | LL | async fn ref_Struct(self: &Struct, f: &u32) -> &u32 { | ---- ---- @@ -9,7 +9,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-struct-async.rs:17:9 + --> $DIR/ref-struct-async.rs:22:9 | LL | async fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 { | ---- ---- @@ -19,7 +19,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-struct-async.rs:21:9 + --> $DIR/ref-struct-async.rs:28:9 | LL | async fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 { | ---- ---- @@ -29,7 +29,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-struct-async.rs:25:9 + --> $DIR/ref-struct-async.rs:34:9 | LL | async fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -39,7 +39,7 @@ LL | f | ^ ...but data from `f` is returned here error[E0623]: lifetime mismatch - --> $DIR/ref-struct-async.rs:29:9 + --> $DIR/ref-struct-async.rs:40:9 | LL | async fn box_pin_Struct(self: Box>, f: &u32) -> &u32 { | ---- ---- diff --git a/src/test/ui/self/elision/ref-struct-async.nll.stderr b/src/test/ui/self/elision/ref-struct-async.nll.stderr index 9361b6f3f81f4..ad07c70df8778 100644 --- a/src/test/ui/self/elision/ref-struct-async.nll.stderr +++ b/src/test/ui/self/elision/ref-struct-async.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/ref-struct-async.rs:13:9 + --> $DIR/ref-struct-async.rs:16:9 | LL | async fn ref_Struct(self: &Struct, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -9,7 +9,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-struct-async.rs:17:9 + --> $DIR/ref-struct-async.rs:22:9 | LL | async fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -19,7 +19,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-struct-async.rs:21:9 + --> $DIR/ref-struct-async.rs:28:9 | LL | async fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -29,7 +29,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-struct-async.rs:25:9 + --> $DIR/ref-struct-async.rs:34:9 | LL | async fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -39,7 +39,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-struct-async.rs:29:9 + --> $DIR/ref-struct-async.rs:40:9 | LL | async fn box_pin_Struct(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/self/elision/ref-struct-async.rs b/src/test/ui/self/elision/ref-struct-async.rs index e6bd5418c8d92..12f8f6faf1b9c 100644 --- a/src/test/ui/self/elision/ref-struct-async.rs +++ b/src/test/ui/self/elision/ref-struct-async.rs @@ -1,4 +1,7 @@ // edition:2018 +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir #![allow(non_snake_case)] @@ -10,23 +13,33 @@ impl Struct { // Test using `&Struct` explicitly: async fn ref_Struct(self: &Struct, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } async fn box_pin_Struct(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } } diff --git a/src/test/ui/self/elision/ref-struct.stderr b/src/test/ui/self/elision/ref-struct.base.stderr similarity index 97% rename from src/test/ui/self/elision/ref-struct.stderr rename to src/test/ui/self/elision/ref-struct.base.stderr index c80993fe8c455..5650b3788e7e3 100644 --- a/src/test/ui/self/elision/ref-struct.stderr +++ b/src/test/ui/self/elision/ref-struct.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/ref-struct.rs:11:9 + --> $DIR/ref-struct.rs:15:9 | LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 { | ---- ---- @@ -15,7 +15,7 @@ LL | fn ref_Struct<'a>(self: &'a Struct, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-struct.rs:15:9 + --> $DIR/ref-struct.rs:21:9 | LL | fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 { | ---- ---- @@ -31,7 +31,7 @@ LL | fn box_ref_Struct<'a>(self: Box<&'a Struct>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-struct.rs:19:9 + --> $DIR/ref-struct.rs:27:9 | LL | fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 { | ---- ---- @@ -47,7 +47,7 @@ LL | fn pin_ref_Struct<'a>(self: Pin<&'a Struct>, f: &'a u32) -> &u32 { | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-struct.rs:23:9 + --> $DIR/ref-struct.rs:33:9 | LL | fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { | ---- ---- @@ -63,7 +63,7 @@ LL | fn box_box_ref_Struct<'a>(self: Box>, f: &'a u32) -> &u | ++++ ++ ++ error[E0623]: lifetime mismatch - --> $DIR/ref-struct.rs:27:9 + --> $DIR/ref-struct.rs:39:9 | LL | fn box_pin_Struct(self: Box>, f: &u32) -> &u32 { | ---- ---- diff --git a/src/test/ui/self/elision/ref-struct.nll.stderr b/src/test/ui/self/elision/ref-struct.nll.stderr index e1cc38b7c952f..70453b0ddfc71 100644 --- a/src/test/ui/self/elision/ref-struct.nll.stderr +++ b/src/test/ui/self/elision/ref-struct.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/ref-struct.rs:11:9 + --> $DIR/ref-struct.rs:15:9 | LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -9,7 +9,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-struct.rs:15:9 + --> $DIR/ref-struct.rs:21:9 | LL | fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -19,7 +19,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-struct.rs:19:9 + --> $DIR/ref-struct.rs:27:9 | LL | fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -29,7 +29,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-struct.rs:23:9 + --> $DIR/ref-struct.rs:33:9 | LL | fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` @@ -39,7 +39,7 @@ LL | f | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/ref-struct.rs:27:9 + --> $DIR/ref-struct.rs:39:9 | LL | fn box_pin_Struct(self: Box>, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/self/elision/ref-struct.rs b/src/test/ui/self/elision/ref-struct.rs index 73711a7feead3..0ffe72793d731 100644 --- a/src/test/ui/self/elision/ref-struct.rs +++ b/src/test/ui/self/elision/ref-struct.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + #![allow(non_snake_case)] use std::pin::Pin; @@ -8,23 +12,33 @@ impl Struct { // Test using `&Struct` explicitly: fn ref_Struct(self: &Struct, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_box_ref_Struct(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn box_pin_Struct(self: Box>, f: &u32) -> &u32 { - f //~ ERROR lifetime mismatch + f + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } } From 9e7a319f0137bd2ffec55cc57f4de5a17f0ceffc Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 17 Apr 2022 22:51:13 +0200 Subject: [PATCH 14/14] Replace u8to64_le macro with u64::from_le_bytes The macro was a reimplementation of the function. --- library/core/tests/hash/sip.rs | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/library/core/tests/hash/sip.rs b/library/core/tests/hash/sip.rs index 5c0e114e93c15..877d084183055 100644 --- a/library/core/tests/hash/sip.rs +++ b/library/core/tests/hash/sip.rs @@ -15,28 +15,6 @@ impl<'a> Hash for Bytes<'a> { } } -macro_rules! u8to64_le { - ($buf:expr, $i:expr) => { - $buf[0 + $i] as u64 - | ($buf[1 + $i] as u64) << 8 - | ($buf[2 + $i] as u64) << 16 - | ($buf[3 + $i] as u64) << 24 - | ($buf[4 + $i] as u64) << 32 - | ($buf[5 + $i] as u64) << 40 - | ($buf[6 + $i] as u64) << 48 - | ($buf[7 + $i] as u64) << 56 - }; - ($buf:expr, $i:expr, $len:expr) => {{ - let mut t = 0; - let mut out = 0; - while t < $len { - out |= ($buf[t + $i] as u64) << t * 8; - t += 1; - } - out - }}; -} - fn hash_with(mut st: H, x: &T) -> u64 { x.hash(&mut st); st.finish() @@ -123,7 +101,7 @@ fn test_siphash_1_3() { let mut state_inc = SipHasher13::new_with_keys(k0, k1); while t < 64 { - let vec = u8to64_le!(vecs[t], 0); + let vec = u64::from_le_bytes(vecs[t]); let out = hash_with(SipHasher13::new_with_keys(k0, k1), &Bytes(&buf)); assert_eq!(vec, out); @@ -217,7 +195,7 @@ fn test_siphash_2_4() { let mut state_inc = SipHasher::new_with_keys(k0, k1); while t < 64 { - let vec = u8to64_le!(vecs[t], 0); + let vec = u64::from_le_bytes(vecs[t]); let out = hash_with(SipHasher::new_with_keys(k0, k1), &Bytes(&buf)); assert_eq!(vec, out);